✅ C++ || 2D dp + Memoization || Easy
\n1. Easy C++\n2. Line by Line Explanation with Comments.\n3. Detailed Explanation \u2705\n4. 2D dp + Memoization.\n5. Please Upvote if it helps\u2B06\uFE0F\n\n
```\n1. Easy C++\n2. Line by Line Explanation with Comments.\n3. Detailed Explanation \u2705\n4. 2D dp + Memoization.\n5. Please Upvote if it helps\u2B06\uFE0F\n```\n\n**EXPLANATION**\n* Base Case-> if piles completed or k coins taken\n* skip current pile and call recursion\n* check for current pile and call recursion for further piles\n* keep max value\n* update memoizated 2d vector\n\n\n\nTIME COMPLEXITY : O(N^N) , N is size of matrix    **Beats 90.02%**\nSPACE COMPLEXITY : O(N^N),                                **Beats 70.50%**\n\n\n\n\n\n\n\n\n\n```\n int solve(int i,vector<vector<int>>&p, int k,vector<vector<int>> &dp){\n        if(i>=p.size() || k<=0) return 0;     //Base Case-> if piles completed or k coins taken\n        if(dp[i][k]!=-1) return dp[i][k];\n        int fur = solve(i+1,p,k,dp), cur=0;   // skip current pile\n        \n        for(int idx=0;idx<p[i].size() && idx<k; idx++){  // check for current pile \n            cur += p[i][idx];\n            fur = max(fur, cur+solve(i+1,p,k-idx-1,dp));  // recursive call for further piles\n        }\n        return dp[i][k]=fur;                 // update dp\n    }\n    \n    int maxValueOfCoins(vector<vector<int>>& p, int k) {\n        vector<vector<int>> dp(p.size(), vector<int>(k+1,-1));\n        return solve(0,p,k,dp);\n    }\n```
['C++']