C++ DP MinMAX solution. N^2
dp[i][j] represent tha maximum different between i to j. and here we use val - dfs() to calculate different, this is a general way to calculate a MinMax value a
dp[i][j] represent tha maximum different between i to j. and here we use val - dfs() to calculate different, this is a general way to calculate a MinMax value and we don\'t need to consider whose turn now.\n```\nclass Solution {\npublic:\n    int dp[1001][1001];\n    int dfs(vector<int>& stones, int left, int right) {\n        if(right == left) return 0;\n        if(dp[left][right] >= 0) return dp[left][right];\n        int res = stones[right] - stones[left] - dfs(stones, left + 1, right);\n        res = max(res, stones[right - 1] - (left > 0 ? stones[left - 1] : 0) - dfs(stones, left, right - 1));\n        return dp[left][right] = res;\n    }\n    int stoneGameVII(vector<int>& stones) {\n        memset(dp, -1, sizeof(dp));\n        for(int i = 1; i < stones.size(); ++i) {\n            stones[i] += stones[i - 1];\n        }\n        return dfs(stones, 0, stones.size() - 1);\n    }\n};\n```
[]