C++ || Memoization || easy to understand
\n\n# Code\n\nclass Solution {\npublic:\n    int helper(vector<vector<int>>& piles, int k, int ind, vector<vector<int>> & dp){\n        if(ind<0)return 0;\n    
\n\n# Code\n```\nclass Solution {\npublic:\n    int helper(vector<vector<int>>& piles, int k, int ind, vector<vector<int>> & dp){\n        if(ind<0)return 0;\n        if(k==0)return 0;\n        if(dp[ind][k]!=-1)return dp[ind][k];\n        int a=helper(piles, k, ind-1, dp);\n        \n        int ans=a;\n        for(int i=0; i<piles[ind].size(); i++){\n            int b=0;\n            if(i+1<=k){\n                b=piles[ind][i]+helper(piles, k-i-1, ind-1, dp);\n                ans=max(ans, b);\n            }\n        }\n        return dp[ind][k]=ans;\n    }\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        int n=piles.size();\n        for(int i=0; i<piles.size(); i++){\n            for(int j=1; j<piles[i].size(); j++){\n                piles[i][j]+=piles[i][j-1];\n            }\n        }\n        vector<vector<int>> dp(n, vector<int>(k+1, -1));\n        return helper(piles, k, n-1, dp);\n    }\n};\n```
['C++']