Bottom-up DP (tabulation)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \nTabulation\n\n# Complex
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nTabulation\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n^2)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n^2)$$\n\n# Code\n```\nclass Solution {\npublic:\n    int maxOperations(vector<int>& nums) {\n        int n = size(nums);\n        set<int> s{nums[0] + nums[1], nums[0] + nums[n - 1], nums[n - 2] + nums[n - 1]};\n        int res{};\n        for (auto &v: s) {\n            vector<vector<int>> dp(n + 1, vector<int>(n + 1));\n            for (int i = 2; i <= n; ++i) {\n                for (int l = 0, r = l + i - 1; r < n; ++l, ++r) {\n                    if (nums[l] + nums[l + 1] == v)\n                        dp[i][l] = max(dp[i][l], 1 + dp[i - 2][l + 2]);\n                    if (nums[l] + nums[r] == v)\n                        dp[i][l] = max(dp[i][l], 1 + dp[i - 2][l + 1]);\n                    if (nums[r - 1] + nums[r] == v)\n                        dp[i][l] = max(dp[i][l], 1 + dp[i - 2][l]);\n                }\n            }\n            res = max(res, dp[n][0]);\n        }\n\n        return res;\n    }\n};\n```
['Dynamic Programming', 'C++']