Easy DP approach
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:O(k*n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\ndepends how you define the dp vector \nIn my case: O(1001*2002);\n# Code\n```\nclass Solution {\nint t[1001][2002];\npublic:\n    int solve(int i, int k, vector<vector<int>>& piles, int n){\n        if (i==n or k<=0)return 0;\n        if (t[i][k]!=-1){return t[i][k];}\n        int ans = solve(i+1,k,piles,n);\n        int temp = 0;\n        for (int kk=0;kk<min((int)piles[i].size(),k);kk++){\n            temp+=piles[i][kk];\n            ans=max(ans,temp + solve(i+1,k-1-kk,piles,n));\n        }\n        return t[i][k]=ans;\n    }\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        int n = piles.size();\n        memset(t,-1,sizeof(t));\n        return solve(0,k,piles,n);\n    }\n};\n```
['Dynamic Programming', 'Prefix Sum', 'C++']