Cpp solution Recursion/DP (beats 98%/97%)
Let the total sum of elements in array be "sum", then if Alice selects (say) i\'th element then Alice\'s current score is "sum-stones[i]". Now if Bob selects sa
Let the total sum of elements in array be "sum", then if Alice selects (say) i\'th element then Alice\'s current score is **"sum-stones[i]"**. Now if Bob selects say some k\'th element (which can be either i+1\'th or j\'th) then Bob\'s current score would be Alice\'s current-stones[k], i.e.**"sum-stones[i]-stones[k]"**. \nSo now the difference between their scores is, **(sum-stones[i])-(sum-stones[i]-stones[k])** which is equal to **stones[k]**, i.e. the stone that bob selected. So, ultimately the difference in scores is just the stones that bob selected and thus bob would want to minimize his stone selection score, which in turn means Alice will also want to minimize her score so that the difference could increase. So just finding what is the minimum score that Bob can get or subtracting the minimum score that ALice can get from total sum will give us the difference.\n```\nclass Solution {\npublic:\n    int a[1001][1001];\n    int solve(int i, int j, vector<int> &v)\n    {\n        if(i>j)\n            return 0;\n        if(a[i][j]!=0)\n            return a[i][j];\n        return a[i][j]=min(v[i]+max(solve(i+2, j, v), solve(i+1, j-1, v)), v[j]+max(solve(i+1, j-1, v), solve(i, j-2, v)));\n    }\n    int stoneGameVII(vector<int>& stones) {\n        memset(a, 0, sizeof(a));\n        int n=stones.size();\n        int sum=accumulate(stones.begin(), stones.end(), 0);\n        int small=solve(0, n-1, stones);\n        //cout<<small<<endl;\n        return sum-small;\n    }\n};\n```\nAny suggestions and comments on improving the code would be welcomed.
[]