C++,Top-Down(Memoization) with Explanation.
Approach:-\n-->This is the DP Approach with Memoization.\n-->We have Choices for any i\'th index Pile. :-\n 1)Either We should not take any Coin from  i\'th ind
**Approach:-**\n-->This is the **DP Approach with Memoization.**\n-->We have Choices for any i\'th index Pile. :-\n 1)Either We should not take any Coin from  i\'th index pile.\n 2)Either we take one top coin from it.\n 3)Either we take 2 consecutive top coin from that pile.\n And So ...on \n -->And After that We call for (i+1)th index Pile.\n ```\nclass Solution {\npublic:\n    int dp[1001][2001]; //Dp array For Memoization.\n    int solve(vector<vector<int>>&v,int index,int coin)\n    {\n        if(index>=v.size()||coin==0)  //Base Condition\n            return 0;\n        if(dp[index][coin]!=-1) //Check wheather It is Already Calculated Or not.\n            return dp[index][coin];\n        \n        \n        /* Our 1st choice :- We not take any Coin from that pile*/\n        int ans=solve(v,index+1,coin); //Just Call function for next Pile.\n        \n       \n        /*Otherwise we can take Coins from that Pile.*/\n        int loop=v[index].size()-1;\n        int sum=0;\n        \n        for(int j=0;j<=min(coin-1,loop);j++) //\n        {\n            sum=sum+v[index][j];\n            ans=max(ans,sum+solve(v,index+1,coin-(j+1)));\n            \n            /*Above we Pass coin-(j+1). Because till j\'th index we have taken j+1 coin from that pile.*/\n        }\n        \n        return dp[index][coin]=ans;\n    }\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        memset(dp,-1,sizeof(dp));\n        return solve(piles,0,k);\n    }\n};\n```\n*If you find it Helpful .Please Upvote.*
['Dynamic Programming', 'Memoization', 'C']