✅Simple DP Solution | Go | C#✅
Go\n\nfunc maxValueOfCoins(piles [][]int, k int) int {\n\tmemo := make([][]int, len(piles)+1)\n\tfor i := range memo {\n\t\tmemo[i] = make([]int, k+1)\n\t}\n\n\
Go\n```\nfunc maxValueOfCoins(piles [][]int, k int) int {\n\tmemo := make([][]int, len(piles)+1)\n\tfor i := range memo {\n\t\tmemo[i] = make([]int, k+1)\n\t}\n\n\treturn dp(piles, memo, 0, k)\n}\n\nfunc dp(piles [][]int, memo [][]int, i int, k int) int {\n\tif k == 0 || i == len(piles) {\n\t\treturn 0\n\t}\n\tif memo[i][k] != 0 {\n\t\treturn memo[i][k]\n\t}\n\n\tres := dp(piles, memo, i+1, k)\n\tcur := 0\n\n\tfor j := 0; j < min(len(piles[i]), k); j++ {\n\t\tcur += piles[i][j]\n\t\tres = max(res, cur+dp(piles, memo, i+1, k-j-1))\n\t}\n\n\tmemo[i][k] = res\n\treturn res\n}\n\nfunc min(a, b int) int {\n\tif a < b {\n\t\treturn a\n\t}\n\treturn b\n}\n\nfunc max(a, b int) int {\n\tif a > b {\n\t\treturn a\n\t}\n\treturn b\n}\n```\nC#\n```\npublic class Solution {\n    public int MaxValueOfCoins(IList<IList<int>> piles, int k) {\n        int n = piles.Count;\n        int[][] memo = new int[n + 1][];\n        for (int i = 0; i <= n; i++) {\n            memo[i] = new int[k + 1];\n            Array.Fill(memo[i], -1);\n        }\n\n        return DP(piles, memo, 0, k);\n    }\n\n    public int DP(IList<IList<int>> piles, int[][] memo, int i, int k) {\n        if (k == 0 || i == piles.Count) return 0;\n        if (memo[i][k] != -1) return memo[i][k];\n\n        int res = DP(piles, memo, i + 1, k);\n        int cur = 0;\n\n        for (int j = 0; j < Math.Min(piles[i].Count, k); ++j) {\n            cur += piles[i][j];\n            res = Math.Max(res, cur + DP(piles, memo, i + 1, k - j - 1));\n        }\n        return memo[i][k] = res;\n    }\n}\n```\n![a6c83c54-1d1a-4f26-8273-b687d119dd5b_1679889261.1494205.png](https://assets.leetcode.com/users/images/cc82e8aa-dc98-4f10-af4c-64b1528c0fb6_1680844232.130332.png)
['Dynamic Programming', 'Recursion', 'Memoization', 'Go', 'C#']