Python, C++ || DP || Prefix Sum || O(N^2)
Python ->\n\nclass Solution:\n    def stoneGameVII(self, stones: List[int]) -> int:\n        n=len(stones)\n        prefix_Sum={-1:0}\n        for i,val in enum
Python ->\n```\nclass Solution:\n    def stoneGameVII(self, stones: List[int]) -> int:\n        n=len(stones)\n        prefix_Sum={-1:0}\n        for i,val in enumerate(stones):\n            prefix_Sum[i]=prefix_Sum[i-1]+val\n        dp=[[0]*n for _ in range(n)]\n        for i in range(n-1,-1,-1):\n            for j in range(i,n):\n                if i!=j:\n                    dp[i][j]=max(prefix_Sum[j]-prefix_Sum[i]-(dp[i+1][j] if i+1<n else 0),prefix_Sum[j-1]-prefix_Sum[i-1]-(dp[i][j-1] if j-1>=0 else 0))\n        return dp[0][n-1]\n        \n```\n\nC++ ->\n```\nclass Solution {\npublic:\n    int stoneGameVII(vector<int>& stones) {\n        int n=stones.size();\n        map <int,int> prefix_Sum;\n        vector<vector<int>> dp(n,vector<int>(n,0));\n        prefix_Sum[-1]=0;\n        for (int i=0;i<n;i++){\n            prefix_Sum[i]=prefix_Sum[i-1]+stones[i];\n        }\n        for (int i=n-1;i>=0;i--){\n            for (int j=i;j<n;j++){\n                if (i!=j){\n                    dp[i][j]=max(prefix_Sum[j]-prefix_Sum[i]-((i+1<n)?dp[i+1][j]:0),prefix_Sum[j-1]-prefix_Sum[i-1]-((j-1>=0)?dp[i][j-1]:0));\n                }\n            }\n        }\n        return dp[0][n-1];\n    }\n};\n```
['Dynamic Programming', 'C', 'Prefix Sum', 'Python']