2D dp top-down approach
Intuition\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 
# Intuition\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```cpp []\nclass Solution {\npublic:\n    int maxCollectedFruits(vector<vector<int>>& fruits) {\n        int n = fruits.size();\n        int c1 = 0;\n        for (int i=0; i<n; i++) {\n            c1 += fruits[i][i];\n            fruits[i][i] = 0;\n        }\n        vector<vector<int>> dp(n, vector<int>(n, -1));\n        int c2 = solve(0, n-1, fruits, n, n-1, dp);\n        vector<vector<int>> dp1(n, vector<int>(n, -1));\n        int c3 = solve1(n-1, 0, fruits, n, n-1, dp1); \n        return c1 + c2 + c3;\n    }\n    int solve(int r, int c, vector<vector<int>>& fruits, int n, int threshold, vector<vector<int>>& dp) {\n        if (r == n-1 && c == n-1) return 0;\n        if (c < n / 2 || threshold <= 0) return -1e9;\n        if (dp[r][c] != -1) return dp[r][c];\n        \n        int res = INT_MIN;\n        for (int j=-1; j<=1; j++) {\n            int newR = r + 1;\n            int newC = c + j;\n            if (newR < n && newC < n) {\n                res = max(res, fruits[r][c] + solve(newR, newC, fruits, n, threshold - 1, dp));\n            }\n        }\n        return dp[r][c] = res;\n    }\n    int solve1(int r, int c, vector<vector<int>>& fruits, int n, int threshold, vector<vector<int>>& dp1) {\n        if (r == n-1 && c == n-1) return 0;\n        if (r < n / 2 || threshold <= 0) return -1e9;\n        if (dp1[r][c] != -1) return dp1[r][c];\n\n        int res = INT_MIN;\n        for (int i=-1; i<=1; i++) {\n            int newR = r + i;\n            int newC = c + 1;\n            if (newR < n && newC < n) {\n                res = max(res, fruits[r][c] + solve1(newR, newC, fruits, n, threshold - 1, dp1));\n            }\n        }\n        return dp1[r][c] = res;\n\n    }\n};\n```
['C++']