2D DP
We search and memoize the maximum value for k coins and i piles. \n\nC++\ncpp\nint dp[1001][2001] = {};\nint maxValueOfCoins(vector<vector<int>>& piles, int k, 
We search and memoize the maximum value for `k` coins and `i` piles. \n\n**C++**\n```cpp\nint dp[1001][2001] = {};\nint maxValueOfCoins(vector<vector<int>>& piles, int k, int i = 0) {\n    if (i == piles.size() || k == 0)\n        return 0;\n    if (dp[i][k] == 0)\n        for (int j = 0, sum = 0; j <= piles[i].size() && k - j >= 0; ++j) {\n            dp[i][k] = max(dp[i][k], sum + maxValueOfCoins(piles, k - j, i + 1));\n            if (j < piles[i].size())\n                sum += piles[i][j];\n        }\n    return dp[i][k];\n}\n```
['C']