choose or dont choose that pile with how many are you going to choose from that pile: is the idea
\nclass Solution {\npublic:\n    \n    int dfs(int npile , int coins, int n,vector<vector<int>>& p,vector<vector<int>> &c)\n    {\n        if(npile>=n || coins 
```\nclass Solution {\npublic:\n    \n    int dfs(int npile , int coins, int n,vector<vector<int>>& p,vector<vector<int>> &c)\n    {\n        if(npile>=n || coins <= 0)\n            return 0;\n        if(c[npile][coins]!=-1)\n            return c[npile][coins];\n        c[npile][coins] = dfs(npile+1,coins,n,p,c);\n        int cpile = 0;\n        for(int j=0;j<min(coins,(int)p[npile].size());j++)\n        {\n            cpile+=p[npile][j];\n            c[npile][coins] = max(c[npile][coins],cpile+dfs(npile+1,coins-1-j,n,p,c));\n        }\n        return c[npile][coins];\n    }\n    int maxValueOfCoins(vector<vector<int>>& p, int k) {\n        \n        int n = p.size();\n        vector<vector<int>> cache(n+1,vector<int> (k+1,-1));\n        return dfs(0,k,n,p,cache);\n    }\n};\n```
['C']