✔💯Easy JAVA Solution ✔💯|| Dynamic Programming
\n\n\n# Code\n\nclass Solution {\n    int dp[][];\n    public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n        int n = piles.size();\n        dp
![upvote.png](https://assets.leetcode.com/users/images/944f8a25-3a7e-4b2c-80ef-3eea96f03fd4_1681555329.6333501.png)\n\n\n# Code\n```\nclass Solution {\n    int dp[][];\n    public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n        int n = piles.size();\n        dp = new int[n+1][k+1];\n        for(int i = 1; i <= n; i++){\n            for(int coins = 0; coins <= k; coins++){\n                dp[i][coins] = -1;\n            }\n        }\n        return helper(piles,n,k);\n    }\n\n    private int helper(List<List<Integer>> piles, int i, int coins){\n        if(i==0)return 0;\n\n        if(dp[i][coins] != -1)return dp[i][coins];\n\n        int currSum = 0;\n        for(int currCoins = 0; currCoins <= Math.min(piles.get(i-1).size(), coins); currCoins++){\n            if(currCoins > 0){\n                currSum += piles.get(i-1).get(currCoins-1);\n            }\n            dp[i][coins] = Math.max(dp[i][coins], helper(piles, i-1, coins-currCoins)+currSum);\n        }\n        return dp[i][coins];\n    }\n}\n```
['Java']