Image Explanation🏆- [Top Down DP - Easy & Concise] - C++/Java/Python
Video Solution (Aryan Mittal) - Link in LeetCode Profile\nMaximum Value of K Coins From Piles by Aryan Mittal\n\n\n\n# Approach & Intution\n\n\n\n\n\n\n\n\n\n# 
# Video Solution (`Aryan Mittal`) - Link in LeetCode Profile\n`Maximum Value of K Coins From Piles` by `Aryan Mittal`\n![lc.png](https://assets.leetcode.com/users/images/9eaa66d1-03e7-4394-93c0-4875df24d5d7_1681526852.9686515.png)\n\n\n# Approach & Intution\n![image.png](https://assets.leetcode.com/users/images/91939f49-936e-4f8b-97d7-3d48ebd5355f_1681522506.1156633.png)\n![image.png](https://assets.leetcode.com/users/images/b1342805-93ea-4693-948d-8c1b0702a36a_1681522520.1675975.png)\n![image.png](https://assets.leetcode.com/users/images/61d2fbf7-ce76-4475-8495-c2697471c49c_1681522531.6415837.png)\n![image.png](https://assets.leetcode.com/users/images/5aab26d9-86f1-4b11-af58-776da724f822_1681522548.880134.png)\n![image.png](https://assets.leetcode.com/users/images/af325b84-0f8b-4825-b3ef-3d2239aed68b_1681522557.3164456.png)\n![image.png](https://assets.leetcode.com/users/images/3af07571-8d76-486f-96df-540499f3110e_1681522565.693431.png)\n![image.png](https://assets.leetcode.com/users/images/319fcde5-983d-4ed5-bba1-29c5ee4eed9a_1681522573.987136.png)\n\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    int func(int i, int k, vector<vector<int>>& piles, vector<vector<int>>& dp){\n        if (dp[i][k] > 0) return dp[i][k];\n        if (i == piles.size() || k == 0) return 0;\n        int res = func(i + 1, k, piles, dp), cur = 0;\n        for (int j = 0; j < piles[i].size() && j < k; ++j) {\n            cur += piles[i][j];\n            res = max(res, func(i + 1, k - j - 1, piles, dp) + cur);\n        }\n        dp[i][k] = res;\n        return res;\n    }\n\n    int maxValueOfCoins(vector<vector<int>>& piles, int K) {\n        int n = piles.size();\n        vector<vector<int>> dp(n + 1, vector<int>(K + 1, 0));\n        return func(0, K, piles, dp);\n    }\n};\n```\n```Java []\nclass Solution {\n    public int func(int i, int k, List<List<Integer>> piles, int[][] dp) {\n        if (dp[i][k] > 0) return dp[i][k];\n        if (i == piles.size() || k == 0) return 0;\n        int res = func(i + 1, k, piles, dp), cur = 0;\n        for (int j = 0; j < piles.get(i).size() && j < k; ++j) {\n            cur += piles.get(i).get(j);\n            res = Math.max(res, func(i + 1, k - j - 1, piles, dp) + cur);\n        }\n        dp[i][k] = res;\n        return res;\n    }\n\n    public int maxValueOfCoins(List<List<Integer>> piles, int K) {\n        int n = piles.size();\n        int[][] dp = new int[n + 1][K + 1];\n        return func(0, K, piles, dp);\n    }\n}\n```\n```Python []\nclass Solution:\n    def maxValueOfCoins(self, piles: List[List[int]], k: int) -> int:\n        \n        @functools.lru_cache(None)\n        def _search(rest_k: int, pile_pos: int) -> int:\n            """Searches for best accumulated coin value starting from pile at position `pile_pos`.\n            \n            Args:\n              - rest_k: The rest of coins we could pick.\n              - pile_pos: The starting position of pile we are working on.\n            """\n            if rest_k == 0 or pile_pos == len(piles): return 0\n\n            # Ignore the current pile and moving to next pile\n            current_mv_found = _search(rest_k, pile_pos+1)\n\n            # Start looking solution with current pile being involved\n            current_pile = piles[pile_pos]\n            accum_coin_value = 0\n            for i in range(min(rest_k, len(current_pile))):\n                # Accumulate the coins\n                accum_coin_value += current_pile[i]\n\n                # Moving to next pile with accumulated coin value in current pile\n                current_mv_found = max(\n                    current_mv_found, \n                    accum_coin_value + _search(rest_k-i-1, pile_pos+1))\n\n            # Return the maximum accumulated coin value found from current pile.\n            return current_mv_found\n\n        # Start searching with initial `k` and first pile\n        return _search(k, 0)\n```\nCredits: Python Solution commented beautifully by @puremonkey2001\n
['Dynamic Programming', 'Recursion', 'C++', 'Java', 'Python3']