Python | DP | O(n^2)
Code\npython3 []\nclass Solution:\n    def maxCollectedFruits(self, fruits: List[List[int]]) -> int:\n        def val(i,j,dp):\n            if 0<=i<n and 0<=j<n
# Code\n```python3 []\nclass Solution:\n    def maxCollectedFruits(self, fruits: List[List[int]]) -> int:\n        def val(i,j,dp):\n            if 0<=i<n and 0<=j<n:\n                return dp[i][j]\n            return 0\n        n = len(fruits)\n        dpT = [[0]*n for _ in range(n)]\n        dpT[0][n-1] = fruits[0][n-1]\n        n = len(fruits)\n        for i in range(1, n):\n            for j in range(max(i+1,n-1-i),n):\n                dpT[i][j] = fruits[i][j]+max(val(i-1,j-1,dpT), val(i-1,j,dpT), val(i-1,j+1,dpT))\n        dpB = [[0]*n for _ in range(n)]\n        dpB[n-1][0] = fruits[n-1][0]\n        for j in range(1,n):\n            for i in range(max(j+1,n-1-j), n):\n                dpB[i][j] = fruits[i][j]+max(val(i,j-1,dpB), val(i-1,j-1,dpB), val(i+1,j-1,dpB))\n        diag = sum([fruits[i][i] for i in range(n)])\n        return dpT[n-2][n-1] + dpB[n-1][n-2] + diag\n                \n                \n            \n```
['Python3']