python3 Solution
\n\nclass Solution:\n    def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n        \n        @functools.lru_cache(None)\n        def dp(i,K):\n
\n```\nclass Solution:\n    def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n        \n        @functools.lru_cache(None)\n        def dp(i,K):\n            if k==0 or i==len(piles):\n                return 0\n\n            res,cur=dp(i+1,K),0\n\n            for j in range(min(len(piles[i]),K)):\n                cur+=piles[i][j]\n                res=max(res,cur+dp(i+1,K-j-1))\n\n            return res\n\n\n        return dp(0,k)          \n```
['Python', 'Python3']