C++ || Memoization || Tabulation
Memoization Code\n\nclass Solution {\npublic:\nint dp[1001][2001];\nint solve(vector<vector<int>> &piles, int idx, int k)\n{\n    if (k == 0)\n        return 0;
# Memoization Code\n```\nclass Solution {\npublic:\nint dp[1001][2001];\nint solve(vector<vector<int>> &piles, int idx, int k)\n{\n    if (k == 0)\n        return 0;\n    if (idx >= piles.size())\n        return 0;\n    if (dp[idx][k] != -1)\n        return dp[idx][k];\n\n    int ans = INT_MIN;\n    int s = 0;\n    int res = solve(piles, idx + 1, k);// if not choosing idxth pile\n    for (int j = 0; j < piles[idx].size() && j<=k-1; j++)\n    {\n       s = s + piles[idx][j];\n       ans = max({ans, s + solve(piles, idx + 1, k - (j + 1)), res});\n    }\n    if (ans < 0) return dp[idx][k] = 0;\n    return dp[idx][k] = ans;\n}\nint maxValueOfCoins(vector<vector<int>> &piles, int k)\n{\n    memset(dp, -1, sizeof(dp));\n    return solve(piles, 0, k);\n}\n};\n```\n# Tabulation Code\n```\nclass Solution {\npublic:\nint solve_tab(vector<vector<int>> &piles, int k)\n{\n    int n = piles.size();\n    vector<vector<int>> dp(n + 1, vector<int>(k + 1, 0));\n\n    // last row and first column initialized with 0\n    // for idx use r and for k use c\n    for (int r = n - 1; r >= 0; r--)\n    {\n        for (int c = 1; c <= k; c++)\n        {\n            int ans = INT_MIN;\n            int s = 0;\n            int res = dp[r+1][c];// if not choosing rth pile\n            for(int j=0; j<piles[r].size() && j<=c-1; j++)\n            {\n                s = s+piles[r][j];\n                ans = max({ ans, s+dp[r+1][c-(j+1)] , res });\n            }\n            if(ans<0) dp[r][c] = 0;\n            else dp[r][c] = ans;\n        }\n    }\n    return dp[0][k];\n}\nint maxValueOfCoins(vector<vector<int>> &piles, int k)\n{\n    return solve_tab(piles, k);\n}\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Prefix Sum', 'C++']