C++ Simple (Recursion + Memorization)
Approach\n Describe your approach to solving the problem. \n1. For each pile we add top coins ans so for any dp[i][k] it will store the max coins we can get fro
# Approach\n<!-- Describe your approach to solving the problem. -->\n1. For each pile we add top coins ans so for any dp[i][k] it will store the max coins we can get from ith pile using k coins.\n2. For a pile we can either choose 0,1,....k coins and then proceede toward next pile.\n# Complexity\n- Time complexity: O(n*m)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n*k)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> aux;\n    int n;\n\n    int rec(vector<vector<int>>& piles, int k,int i){\n        if(i==n){return 0;}\n        if(aux[i][k]==-1){\n            aux[i][k]=rec(piles,k,i+1);\n            // Loop will run till ith pile is empty OR we can\'t pick any more coins i.e k==0\n            for(int j=0,x=0; j<piles[i].size() && k-j-1>=0; j++){\n                x+=piles[i][j];\n                aux[i][k]=max(aux[i][k],rec(piles,k-j-1,i+1)+x);\n            }\n        }\n        return aux[i][k];\n    }\n\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        n=piles.size();\n        aux.resize(n,vector<int>(k+1,-1));    \n        return rec(piles,k,0);\n    }\n};\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']