[c++] 27 ms 100%
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 []\ntypedef long long ll;\nclass Solution {\npublic:\n    int n;\n    ll sum = 0;\n    ll cal(vector<vector<int>>& fs)\n    {\n        int x = n - 1;\n        int y = 0;\n        vector<int> dp(n, 0);\n        vector<int> tmp(n, 0);\n        dp[n - 1] = fs[n - 1][0];\n        for (int j = 1; j < n; j++)\n        {\n            int e = max(n - 1 - j, 0);\n            e = max(e, j);\n            for (int i = n - 1; i >= e; i--)\n            {\n                tmp[i] = dp[i] + fs[i][j];\n                if (i - 1 >= 0) tmp[i] = max(tmp[i], dp[i - 1] + fs[i][j]);\n                if (i + 1 < n)  tmp[i] = max(tmp[i], dp[i + 1] + fs[i][j]);\n            }\n            swap(dp, tmp);\n        }\n        return dp[n - 1];\n    }\n    int maxCollectedFruits(vector<vector<int>>& fs) {\n        n = fs.size();\n        for (int i = 0; i < n; i++) \n        { sum += fs[i][i];\n            fs[i][i] = 0;\n        }\n        ll a = cal(fs);\n\n        for (int i = 0; i < n; i++)\n        {\n            for (int j = i + 1; j < n; j++)\n            {\n                swap(fs[i][j], fs[j][i]);\n            }\n        }\n        ll b = cal(fs);\n        cout << sum << "," << a << "," << b << endl;\n        return sum + a + b;\n    }\n};\n```
['C++']