C++ || 2D DP
\nclass Solution {\npublic:\n    \n    int dp[2001][2001];\n    \n    int helper(int idx,vector<vector<int>>& preffix,int k){\n        \n        if(idx >= preff
```\nclass Solution {\npublic:\n    \n    int dp[2001][2001];\n    \n    int helper(int idx,vector<vector<int>>& preffix,int k){\n        \n        if(idx >= preffix.size() || k<=0){\n            return 0;\n        }\n        \n        if(dp[idx][k] != -1){\n            return dp[idx][k];\n        }\n        \n        int max_score = INT_MIN;\n        \n        \n        for(int i=0;i<=k && i<=preffix[idx].size();i++){\n             int sum = 0;\n            \n             if(i>0){\n                sum += preffix[idx][i-1];      \n             }\n           \n             int score = helper(idx+1,preffix,k-i) + sum;\n             max_score = max(max_score,score);   \n        }\n       \n        return dp[idx][k] = max_score;\n    }\n    \n    int maxValueOfCoins(vector<vector<int>>& piles, int k){\n        memset(dp,-1,sizeof(dp));\n        \n        vector<vector<int>> preffix;\n        \n        for(int i=0;i<piles.size();i++){\n            vector<int> v(piles[i].size());\n            v[0] = piles[i][0];\n            \n            \n            for(int j=1;j<piles[i].size();j++){\n                v[j] = piles[i][j] + v[j-1];\n            }\n            \n            preffix.push_back(v);\n        }\n       \n        return helper(0,preffix,k);\n    }\n};\n```
['Dynamic Programming']