C++ || Dynamic Programming
Code\n\nclass Solution {\npublic:\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        int n = piles.size();\n        \n        int dp[n+1][k+
# Code\n```\nclass Solution {\npublic:\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        int n = piles.size();\n        \n        int dp[n+1][k+1];\n        memset(dp,0,sizeof(dp));\n\n        for(int i=1; i<=n; i++)\n        {\n            int sz = piles[i-1].size();\n            for(int j=1; j<=k; j++)\n            {\n                int tmp = dp[i-1][j];\n                int curr = 0, s = 0;\n                for(int t=1; t<=sz; t++)\n                {\n                    s += piles[i-1][t-1];\n                    if(j-t >= 0)\n                        curr = max(curr, dp[i-1][j-t] + s);\n\n                    dp[i][j] = max(dp[i-1][j], curr);\n                }\n            }\n        }\n\n        return dp[n][k];\n    }\n};\n```
['Dynamic Programming', 'C++']