C++ | Easy 3D DP
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```\nclass Solution {\npublic:\n    int dp[2000][2000][3];\n    int solve(int i,int j,int sumInd,vector<int>&nums,vector<int>&sum)\n    {\n        if(i>=j)return 0;\n        \n        if(dp[i][j][sumInd]!=-1)return dp[i][j][sumInd];\n        int maxi=0;\n        int sum1=nums[i]+nums[i+1];\n        int sum2=nums[j-1]+nums[j];\n        int sum3=nums[i]+nums[j];\n        \n        int Sum=sum[sumInd];\n        if(Sum==sum1)\n        {\n            maxi=max(maxi,1+solve(i+2,j,sumInd,nums,sum));\n        }\n        if(Sum==sum2)\n        {\n            maxi=max(maxi,1+solve(i,j-2,sumInd,nums,sum));\n        }\n        if(Sum==sum3)\n        {\n            maxi=max(maxi,1+solve(i+1,j-1,sumInd,nums,sum));\n        }\n        return dp[i][j][sumInd]=maxi;\n        \n    }\n    int maxOperations(vector<int>& nums) {\n        int n=nums.size();\n        int sum1=nums[0]+nums[1];\n        int sum2=nums[n-2]+nums[n-1];\n        int sum3=nums[0]+nums[n-1];\n        vector<int>sum={sum1,sum2,sum3};\n        // vector<vector<vector<int>>>dp(n,vector<vector<int>>(n,vector<int>(3,-1)));\n        memset(dp,-1,sizeof(dp));\n        int ans=0;\n        for(int i=0;i<3;i++)\n            ans=max(ans,solve(0,n-1,i,nums,sum));\n        return ans;\n        \n    }\n};\n```
['C++']