Memoization | C++
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 ans;\n    int helper(vector<int>& nums,int left,int right,int score,int ops,vector<vector<int>>& dp){\n        if((right-left+1)<2){\n            return 0;\n        }\n        if(dp[left][right]!=-1){\n            return dp[left][right];\n        }\n        int takeFront=0,takeRear=0,takeOne=0;\n        if(nums[left]+nums[left+1]==score || score==INT_MIN){\n            ans=max(ans,ops+1);\n            takeFront=nums[left]+nums[left+1]+helper(nums,left+2,right,nums[left]+nums[left+1],ops+1,dp);\n        }\n        if(nums[right]+nums[right-1]==score || score==INT_MIN){\n            ans=max(ans,ops+1);\n            takeFront=nums[right]+nums[right-1]+helper(nums,left,right-2,nums[right]+nums[right-1],ops+1,dp);\n        }\n        if(nums[left]+nums[right]==score || score==INT_MIN){\n            ans=max(ans,ops+1);\n            takeFront=nums[left]+nums[right]+helper(nums,left+1,right-1,nums[left]+nums[right],ops+1,dp);\n        }\n        return dp[left][right]=max({takeFront,takeRear,takeOne});\n    } \n    int maxOperations(vector<int>& nums) {\n        ans=0;\n        vector<vector<int>> dp(nums.size()+1,vector<int>(nums.size()+1,-1));\n        helper(nums,0,nums.size()-1,INT_MIN,0,dp);\n        return ans;\n    }\n};\n```
['C++']