Easy C++ Dp --> Memoization->Tabulation with Prefix Sum
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\nMEMOIZATION\n```\nclass Solution {\npublic:\n    int solve(int i,int k,vector<vector<int>>& dp,vector<vector<int>>& piles)\n    {\n        if(k==0)return 0;\n        if(i>=piles.size())return 0;\n        if(dp[i][k]!=-1)return dp[i][k];\n        int np = solve(i+1,k,dp,piles);\n        int p=0;\n        for(int ind=0;ind<piles[i].size();ind++)\n        {\n            if(ind+1<=k)\n            {\n                p=max(p,piles[i][ind]+solve(i+1,k-ind-1,dp,piles));\n            }\n            else\n            {\n                break;\n            }\n        }\n        return dp[i][k]=max(p,np);\n    }\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        \n        int n=piles.size();\n        for(int i=0;i<n;i++)\n            for(int j=1;j<piles[i].size();j++)\n                piles[i][j]=piles[i][j]+piles[i][j-1];\n        vector<vector<int>> dp(n+1,vector<int> (k+1,-1));\n        return solve(0,k,dp,piles);        \n    }\n};\n```\nTABULATION\n```\n int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        \n        int n=piles.size();\n        for(int i=0;i<n;i++)\n            for(int j=1;j<piles[i].size();j++)\n                piles[i][j]=piles[i][j]+piles[i][j-1];\n        vector<vector<int>> dp(n+1,vector<int> (k+1,0));\n        for(int i=n-1;i>=0;i--)\n        {\n            for(int j=1;j<=k;j++)\n            {\n                int np = dp[i+1][j];\n                int p=0;\n                for(int ind=0;ind<piles[i].size();ind++)\n                {\n                    if(ind+1<=j)\n                    {\n                        p=max(p,piles[i][ind]+dp[i+1][j-ind-1]);\n                    }\n                    else\n                    {   \n                        break;\n                    }\n                }\n                dp[i][j]=max(p,np); \n            }\n        }return dp[0][k];\n\n        //return solve(0,k,dp,piles);        \n    }\n```
['C++']