Simple and Precise | Simple | Recursive | Intuitive | Beginners Game Strategy
```\nclass Solution {\npublic:\n    vector> dp;\n    int fun(int i,int j,vector &arr,vector &pre){\n        //Base Case \n        if(i +1== j){\n            ret
```\nclass Solution {\npublic:\n    vector<vector<int>> dp;\n    int fun(int i,int j,vector<int> &arr,vector<int> &pre){\n        //Base Case \n        if(i +1== j){\n            return max(arr[i],arr[i+1]);\n        }\n        if(i == j) return 0;\n        if(i > j) return 0;\n        if(dp[i][j] != -1) return dp[i][j];\n        int L = pre[j] - pre[i];\n        int R = (j == 0 ? 0 : pre[j-1]) - (i == 0 ? 0 : pre[i-1]);\n        \n        int L1 = fun(i+2,j,arr,pre);\n        int L2 = fun(i+1,j-1,arr,pre);\n        \n        int R1 = fun(i+1,j-1,arr,pre);\n        int R2 = fun(i,j-2,arr,pre);\n    \n    \n        int l1 = pre[j] - pre[i+1]; \n        int l2 = (j == 0 ? 0 : pre[j-1]) - pre[i];\n        int r1 = (j - 1 < 0 ? 0 : pre[j-1]) - pre[i];\n        int r2 = (j-2 <0 ? 0 : pre[j-2]) - (i-1<0 ? 0 : pre[i-1]);\n        \n        int ans = max(L + min(L1-l1,L2-l2),R + min(R1-r1,R2-r2));\n        \n        return dp[i][j] = ans;\n    }\n    \n    int stoneGameVII(vector<int>& arr) {\n        int n = arr.size();\n        vector<int> pre(n);\n        pre[0] = arr[0];\n        for(int i=1;i<n;i++) pre[i] = pre[i-1] + arr[i];\n        dp = vector<vector<int>> (n,vector<int> (n,-1));\n        return fun(0,n-1,arr,pre);\n    }\n};
['Dynamic Programming', 'Recursion']