Python 3   ||   9 lines,  recursion   ||   T/S: 78% / 91%
\nclass Solution:\n    def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n        \n        @lru_cache(None)\n        def dfs(coins, moves):\n  
```\nclass Solution:\n    def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n        \n        @lru_cache(None)\n        def dfs(coins, moves):\n            if len(piles) == coins: return 0\n\n            ans, curr, pile = dfs(coins+1, moves), 0, piles[coins]\n\n            for j in range(min(len(pile), moves)):\n                curr += pile[j]\n                ans = max(ans, curr + dfs(coins+1, moves-j-1))\n\n            return ans\n        \n        return dfs(0,k)\n```\n[https://leetcode.com/problems/maximum-value-of-k-coins-from-piles/submissions/1286535343/\n](https://leetcode.com/problems/maximum-value-of-k-coins-from-piles/submissions/1286535343/\n)\nI could be wrong, but I think that time complexity is *O*(*N* * *K*) and space complexity is *O*(*N* * *K*).
['Python3']