Single Cache
With a bit of coniseration, we can see that you cannot arrive at [i, j] subarray with different scores.\n\nTherefore, we only need one dp cache for 3 possible s
With a bit of coniseration, we can see that you cannot arrive at `[i, j]` subarray with different scores.\n\nTherefore, we only need one `dp` cache for `3` possible scores.\n\n**C++**\n```cpp\nint dp[2001][2001] = {};\nint dfs(int i, int j, int s, vector<int>& n) {\n    if (i >= j)\n        return 0;\n    if (dp[i][j] == 0)\n        dp[i][j] = 1 + max({\n            s == 0 || n[i] + n[i + 1] == s ? 1 + dfs(i + 2, j, n[i] + n[i + 1], n) : 0,\n            s == 0 || n[j] + n[j - 1] == s ? 1 + dfs(i, j - 2, n[j] + n[j - 1], n) : 0,\n            s == 0 || n[i] + n[j] == s ? 1 + dfs(i + 1, j - 1, n[i] + n[j], n) : 0\n        });\n    return dp[i][j] - 1;\n}\nint maxOperations(vector<int>& n) {\n    return dfs(0, n.size() - 1, 0, n);\n}\n```
['C']