Partition DP
Intuition\n Describe your first thoughts on how to solve this problem. \nEach child can move only in his own area according to the condition of the number of st
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nEach child can move only in his own area according to the condition of the number of steps\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nAreas:\n![image.png](https://assets.leetcode.com/users/images/81d560fd-0c12-4868-9a47-18be7272529f_1732378080.8769667.png)\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```golang []\n\nfunc maxCollectedFruits(fruits [][]int) int {\n\tn := len(fruits)\n\tgreen, red, blue := 0, 0, 0\n\tfor i := 0; i < n; i++ {\n\t\tgreen += fruits[i][i]\n\t\tfruits[i][i] = 0\n\t}\n\n\tfor i := 0; i < n; i++ {\n\t\tfor j := 0; j < n; j++ {\n\t\t\tif j < n-i-1 {\n\t\t\t\tfruits[i][j] = 0\n\t\t\t}\n\t\t}\n\t}\n\t//red\n\tfor i := 1; i < n-1; i++ {\n\t\tfor j := i + 1; j < n; j++ {\n\t\t\tvar l, m, r int\n\t\t\tif j-1 >= 0 {\n\t\t\t\tl = fruits[i-1][j-1]\n\t\t\t}\n\t\t\tm = fruits[i-1][j]\n\t\t\tif j+1 < n {\n\t\t\t\tr = fruits[i-1][j+1]\n\t\t\t}\n\t\t\tfruits[i][j] += max(max(l, m), r)\n\t\t}\n\t}\n\t//blue\n\tfor j := 1; j < n-1; j++ {\n\t\tfor i := n - 1; i >= n-1-i; i-- {\n\t\t\tvar u, m, d int\n\t\t\tif i-1 >= 0 {\n\t\t\t\tu = fruits[i-1][j-1]\n\t\t\t}\n\t\t\tm = fruits[i][j-1]\n\t\t\tif i+1 < n {\n\t\t\t\td = fruits[i+1][j-1]\n\t\t\t}\n\t\t\tfruits[i][j] += max(max(u, m), d)\n\t\t}\n\t}\n\n\t//fmt.Println(fruits)\n\tred = fruits[n-2][n-1]\n\tblue = fruits[n-1][n-2]\n\treturn green + red + blue\n}\n```
['Dynamic Programming', 'Go']