✅ Recursion | Memoization | Tabulation | C++ | Striver | Beginner friendly solution ✅
Intuition\nSimple pick or not pick approach. For pick we run a for loop through the array.  \n Describe your first thoughts on how to solve this problem. \n\n# 
# Intuition\nSimple pick or not pick approach. For pick we run a for loop through the array.  \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\n```\n# Recusive code which will give you TLE\n\nint sumi(int ind, vector<vector<int>> &piles, int k, int n){\n    if(ind==n or k==0) return 0;\n    int notPick=sumi(ind+1,piles,k,n);\n    int pick=0,coins=k,sum=0;\n    for(int i=0;i<piles[ind].size() and coins>0;i++){\n        sum+=piles[ind][i];\n        coins--;\n        int x=sum+sumi(ind+1,piles,coins,n);\n        pick=max(pick,x);\n    }\n    return max(pick,notPick);\n}\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        int n=piles.size();\n        int ind=0;\n        return sumi(ind,piles,k,n);\n    }\n```\n\n\n\n\n```\n# Memoized Solution of above\nclass Solution {\npublic:\n\nint sumi(int ind, vector<vector<int>> &piles, int k, int n, vector<vector<int>> &dp){\n    if(ind==n or k==0) return 0;\n    if(dp[ind][k]!=-1) return dp[ind][k];\n    int notPick=sumi(ind+1,piles,k,n,dp);\n    int pick=0,coins=k,sum=0;\n    for(int i=0;i<piles[ind].size() and coins>0;i++){\n        sum+=piles[ind][i];\n        coins--;\n        int x=sum+sumi(ind+1,piles,coins,n,dp);\n        pick=max(pick,x);\n    }\n    return dp[ind][k]=max(pick,notPick);\n}\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        int n=piles.size();\n        int ind=0;\n        vector<vector<int>> dp(n, vector<int> (k+1,-1));\n        return sumi(ind,piles,k,n,dp);\n    }\n};\n```\n```\n# Tabulation\nclass Solution {\npublic:\n    int maxValueOfCoins(vector<vector<int>>& piles, int k) {\n        int n=piles.size();\n        vector<vector<int>> dp(n, vector<int> (k+1,0));\n        for(int i=0;i<n;i++){\n            dp[i][0]=0;\n        }\n        int sum=0;\n        for(int i=1;i<=k and i<=piles[0].size();i++){\n            sum+=piles[0][i-1];\n            dp[0][i]=sum;\n        }\n        for(int i=1;i<n;i++){\n            for(int j=1;j<=k;j++){\n                int notPick=dp[i-1][j];\n                int pick=0;\n                int sum=0;\n                for(int k=1;k<=j and k<=piles[i].size();k++){\n                    sum+=piles[i][k-1];\n                    pick=max(pick,sum+dp[i-1][j-k]);\n                }\n                dp[i][j]=max(pick,notPick);\n            }\n        }\n        return dp[n-1][k];\n    }\n};\n```\n# ***Please upvote if it helped!***
['C++']