C++ SOLUTION WITH DP(MEMOIZATION)
\nclass Solution {\npublic:\n    int check(vector<int> &s,int i,int n,int sum,vector<vector<int>> &dp)\n    {\n        if(i==n)\n            return(0);\n       
```\nclass Solution {\npublic:\n    int check(vector<int> &s,int i,int n,int sum,vector<vector<int>> &dp)\n    {\n        if(i==n)\n            return(0);\n        if(dp[i][n]!=-1)\n            return(dp[i][n]);\n        return(dp[i][n]=max(sum-s[i]-check(s,i+1,n,sum-s[i],dp),sum-s[n]-check(s,i,n-1,sum-s[n],dp)));\n    }\n    int stoneGameVII(vector<int>& s) {\n        int n=s.size();\n        vector<vector<int>> dp(n,vector<int>(n,-1));\n        int sum=accumulate(s.begin(),s.end(),0);\n        return(check(s,0,n-1,sum,dp));\n    }\n};\n```
[]