Easy C++ 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:\nO(n*n)\n\n- Space complexity:\nO(n*n)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int dp[1001][1001];\n    int child2(int i,int j,vector<vector<int>>& f,int n)\n    {\n        if(i<0 || j<0 || i>=n || j>=n || i<j) return -1e9;\n         if(i==j && i!=n-1) return -1e9;\n        if(i==n-1 && j==n-1) return 0;\n        if(dp[i][j]!=-1) return dp[i][j];\n        int first = child2(i-1,j+1,f,n)+f[i][j];\n        int second = child2(i,j+1,f,n)+f[i][j];\n        int third = child2(i+1,j+1,f,n)+f[i][j];\n        return dp[i][j]= max({first,second,third});\n    }\n\n    int child3(int i,int j,vector<vector<int>>& f,int n)\n    {\n        if(i<0 || j<0 || i>=n || j>=n || i>j) return -1e9;\n        if(i==j && i!=n-1) return -1e9;\n        if(i==n-1 && j==n-1) return 0;\n        if(dp[i][j]!=-1) return dp[i][j];\n        int first = child3(i+1,j-1,f,n)+f[i][j];\n        int second = child3(i+1,j,f,n)+f[i][j];\n        int third = child3(i+1,j+1,f,n)+f[i][j];\n        return dp[i][j] = max({first,second,third});\n    }\n    int maxCollectedFruits(vector<vector<int>>& f) {\n        int n=f.size();\n        int a=0;\n        for(int i=0;i<n;i++)\n        {\n            a+=f[i][i];\n        }\n         memset(dp,-1,sizeof(dp));\n        int b = child2(n-1,0,f,n);\n         memset(dp,-1,sizeof(dp));\n        int c =child3(0,n-1,f,n);\n\n        return a+b+c;\n    }\n};\n```
['Dynamic Programming', 'C++']