[Java] Knapsack variation | Dynammic Programming | Easy to undestand,
TC - O(N*M) \nn=size of piles,\nm=size of piles[i]\n\nclass Solution {\n    public int helper(List> piles,int idx,int k,int [][]dp){\n        \n        if(idx<0
TC - O(N*M) \nn=size of piles,\nm=size of piles[i]\n\nclass Solution {\n    public int helper(List<List<Integer>> piles,int idx,int k,int [][]dp){\n        \n        if(idx<0 || k == 0) return 0;\n        if(dp[idx][k] != -1) return dp[idx][k];\n        \n    \n        // exclude case \n        int exclude = helper(piles,idx-1,k,dp);\n        \n        \n        // include case\n        int sum = 0;\n        int include = 0;\n        \n        List<Integer> curr_pile = piles.get(idx);\n        \n        for(int i=0;i<Math.min(curr_pile.size(),k);i++){\n            sum += curr_pile.get(i);\n            include = Math.max(sum + helper(piles,idx-1,k-i-1,dp),include);\n        }\n        return dp[idx][k] = Math.max(include,exclude);\n    }\n    public int maxValueOfCoins(List<List<Integer>> piles, int k) {\n       \n        int n = piles.size();\n        int [][]dp = new int[n+1][k+1];\n        for(int []d:dp) Arrays.fill(d,-1);\n        \n        return helper(piles,n-1,k,dp);\n    }\n}
['Array', 'Dynamic Programming', 'Memoization', 'Java']