Basic Approach (Java) (DP)
Code\n\nclass Solution {\n    public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n        //dp[i][j] means when we just use the first i piles and j 
# Code\n```\nclass Solution {\n    public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n        //dp[i][j] means when we just use the first i piles and j picks, the maximum coins we can get\n        int[][] dp = new int[piles.size()+1][k+1];\n        for (int i = 1; i <= piles.size(); i++){\n            for (int j = 1; j <= k; j++){\n                int sum = 0;\n                // At first we don\'t pick anything, so the coins you can get is the same and for i-1 condition\n                dp[i][j] = dp[i-1][j];\n                //Begin to traverse the ith pile\n                //Note here we use min function to prevent index out of bound\n                for (int h = 0; h < Math.min(j, piles.get(i-1).size()); h++){\n                    //We take the current (hth) coin\n                    sum += piles.get(i-1).get(h);\n                    //Check if pick it can maximize our score\n                    //Note that if we pick it, we can only get the coins for j-1-h picks when we are at i-1th coin\n                    dp[i][j] = Math.max(dp[i][j], sum + dp[i-1][j-1-h]);\n                }\n            }\n        }\n        //The result is when we use all of the piles and k picks\n        return dp[piles.size()][k]; \n    }\n}\n```
['Dynamic Programming', 'Java']