C++ Super Simple and Clear Solution
\nclass Solution {\npublic:\n    int rec(vector<int>& stones, int start, int end, int sum) {\n        if (start == end) \n            return 0;\n        \n     
```\nclass Solution {\npublic:\n    int rec(vector<int>& stones, int start, int end, int sum) {\n        if (start == end) \n            return 0;\n        \n        if (dp[start][end]) \n            return dp[start][end];\n        \n        int remove_first = sum - stones[start] - rec(stones, start+1, end, sum-stones[start]);\n        int remove_last = sum - stones[end] - rec(stones, start, end-1, sum-stones[end]);\n        \n        dp[start][end] = max(remove_first, remove_last);\n        return dp[start][end];\n        \n    }\n    int stoneGameVII(vector<int>& stones) {\n        dp.assign(stones.size(), vector<int>(stones.size(), 0));\n        int sum = 0;\n        sum = accumulate(stones.begin(), stones.end(), sum);\n        return rec(stones, 0, stones.size()-1, sum);\n    }\n    \nprivate:\n    vector<vector<int>> dp;\n};\n```
['C']