Top down approach | Python3 | Intuitive solution
Please UpvoteCode
# Please Upvote

# Code
```python3 []
from typing import List
from functools import lru_cache

class Solution:
    def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:
        n = len(piles)
        prefixSums = []
        for pile in piles:
            cur = [0]
            for coin in pile:
                cur.append(cur[-1] + coin)
            prefixSums.append(cur)
        
        @lru_cache(maxsize=None)
        def dp(i, r):
            if i == n or r == 0:
                return 0
            
            best = dp(i + 1, r)

            for j in range(1, min(len(prefixSums[i]), r + 1)):
                best = max(best, prefixSums[i][j] + dp(i + 1, r - j))
            
            return best
        
        return dp(0, k)

```
['Array', 'Dynamic Programming', 'Memoization', 'Prefix Sum', 'Python3']