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:O(n*n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(n * n)+O((n-1)*(n-1))\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    int f(int i,int j,int score,int operation,vector<int>&nums,vector<vector<int>>&dp){\n        if(i>=j){\n            return operation;\n        }\n        if((nums[i]+nums[j]!=score) &&(nums[i]+nums[i+1]!=score) &&(nums[j]+nums[j-1]!=score) && score!=0) return operation;\n        if(dp[i][j]!=-1)return dp[i][j];\n        int maxi=INT_MIN;\n        if(score==0 ||(score==nums[i]+nums[i+1]))\n        maxi=max(maxi,f(i+2,j,nums[i]+nums[i+1],operation+1,nums,dp));\n\n        if(score==0 ||(score==nums[i]+nums[j]))\n        maxi=max(maxi,f(i+1,j-1,nums[i]+nums[j],operation+1,nums,dp));\n\n        if(score==0 ||(score==nums[j]+nums[j-1]))\n        maxi=max(maxi,f(i,j-2,nums[j]+nums[j-1],operation+1,nums,dp));\n        return dp[i][j]=maxi;\n    }\n    int maxOperations(vector<int>& nums) {\n        int n=nums.size();\n        int score=0;\n        vector<vector<int>>dp(n,vector<int>(n,-1));\n        return f(0,n-1,score,0,nums,dp);\n    }\n};\n```
['C++']