Solution in C++
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> dp;\n    int func(vector<vector<int>>& p,int i,int k)\n    {\n        if(i==p.size()) return 0;\n        if(dp[i][k]!=-1) return dp[i][k];\n        int ans=func(p,i+1,k);\n        int a=0;\n        for(int j=0;j<p[i].size()&&j<k;j++)\n        {\n            a+=p[i][j];\n            ans=max(ans,a+func(p,i+1,k-j-1));\n        }\n        return dp[i][k]=ans;\n    }\n    int maxValueOfCoins(vector<vector<int>>& p, int k) \n    {\n        dp=vector<vector<int>>(p.size(),vector<int>(k+1,-1));\n        return func(p,0,k);\n    }\n};\n```
['C++']