c++|| DP || memoization || Easy to understand
\nclass Solution {\npublic:\n    int fun(vector<int>& stones,int i,int j,int sum,vector<vector<int>>&dp)\n    {\n        if(i>j) return 0;\n        \n        if
```\nclass Solution {\npublic:\n    int fun(vector<int>& stones,int i,int j,int sum,vector<vector<int>>&dp)\n    {\n        if(i>j) return 0;\n        \n        if(dp[i][j]!=-1) return dp[i][j];\n        \n        int res=0;\n        res=max(res,(sum-stones[i])-fun(stones,i+1,j,sum-stones[i],dp));\n        res=max(res,(sum-stones[j])-fun(stones,i,j-1,sum-stones[j],dp));\n        dp[i][j]=res;\n        return res;\n    }\n    int stoneGameVII(vector<int>& stones) {\n        int sum=accumulate(stones.begin(),stones.end(),0);\n        int n=stones.size();\n        vector<vector<int>> dp(n,vector<int>(n,-1));\n        return fun(stones,0,stones.size()-1,sum,dp);\n    }\n};\n```
[]