C++ | Recursion + DP
Code\n\nclass Solution {\npublic:\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        \n        vector<vector<int>> dp(piles.size(), vector<i
# Code\n```\nclass Solution {\npublic:\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        \n        vector<vector<int>> dp(piles.size(), vector<int> (k + 1, -1));\n        return helper(piles, 0, k, dp);\n    }\n\n    int helper(vector<vector<int>> &piles, int i, int k, vector<vector<int>> &dp)\n    {\n        if(i >= piles.size() || k == 0)\n            return 0;\n\n        if(dp[i][k] != -1)\n            return dp[i][k];\n\n        int mx = helper(piles, i + 1, k, dp), sum = 0;\n        for(int j = 0; j < piles[i].size() && j < k; j++)\n            mx = max(mx, (sum += piles[i][j]) + helper(piles, i + 1, k - j - 1, dp));\n\n        return dp[i][k] = mx;\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']