C++ | 2D - DP
\nclass Solution {\npublic:\n    int maxValueOfCoins(vector<vector<int>>& P, int k) {\n        int m = P.size();\n        for(int i = 0 ; i< m ; i++){\n        
```\nclass Solution {\npublic:\n    int maxValueOfCoins(vector<vector<int>>& P, int k) {\n        int m = P.size();\n        for(int i = 0 ; i< m ; i++){\n            int n = P[i].size();\n            for(int j = 1 ; j<n; ++j){\n                P[i][j] += P[i][j-1];\n            }\n        }// sum of value if we take j elements from top of any pile of coins.\n        vector<int> mxc(k+1,0);\n        for(int j = min(k,(int)P[0].size()) ; j>0; --j){\n            mxc[j] = P[0][j-1];\n        }\n        for(int i = 1 ; i< m ; i++){\n            int n = P[i].size();\n            for(int j=k; j>0 ; --j){//Final Sum\n                for(int l=min(j,n); l>0; --l){\n                    mxc[j] = max(mxc[j-l]+P[i][l-1],mxc[j]);\n                }\n                 \n            }\n        }\n        return mxc[k];\n        \n    }\n};\n```\n\n0-1 Knapsack problem variant.
[]