C++ Solution explained and commented
\nclass Solution {\npublic:\n    /*\nLogic:Alice and Bob have to choose from either of the left or right most part \nand then his score will become sum of the r
```\nclass Solution {\npublic:\n    /*\nLogic:Alice and Bob have to choose from either of the left or right most part \nand then his score will become sum of the remainning stone .So for this we \nneed to first calculate sum for the stones vector and then you have two choices--->\n    1)choose left stone and then score will be total sum-choosen stone and recur for remainning stone but sum will become total sum-choosen stone.\n    2)choose right stone and then score will be total sum-choosen stone and recur for remainning stone but sum will become total sum-choosen stone.\n        Now you need to maximize the score difference so just maximum between these two.\n        */\n    //initialize table for memorization\n    int dp[1005][1005];\n    int solve(vector<int>&v,int i,int j,int sum)\n    {\n        //base case\n        if(i>j)\n            return 0;\n        //memorized step\n        else if(dp[i][j]!=-1)\n            return dp[i][j];\n        //ans will max between your two choices i.e left or right one\n        int ans=max(sum-v[i]-solve(v,i+1,j,sum-v[i]),sum-v[j]-solve(v,i,j-1,sum-v[j]));\n        return dp[i][j]=ans;\n    }\n    int stoneGameVII(vector<int>& v) {\n        //initialize sum \n        int n=v.size(),sum=0;\n        //calculate sum\n        for(int i=0;i<n;i++)\n            sum+=v[i];\n        memset(dp,-1,sizeof(dp));\n        //call solve to return ans.\n        return solve(v,0,n-1,sum);\n    }\n};\ndo upvote if you find it useful.......\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'C', 'C++']