Recursion->Memoization->Tabulation
Intuition\n Describe your first thoughts on how to solve this problem. \n\nAlice Turn\n        [5 3 1 4 2]\n        A = 5 + 3 + 1 + 4 = 13 \nBob Turn\n        [
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n```\nAlice Turn\n        [5 3 1 4 2]\n        A = 5 + 3 + 1 + 4 = 13 \nBob Turn\n        [5 3 1 4]\n        B = 3 + 1 + 4 = 8\nAlice Turn\n        [3 1 4]\n        A = 1 + 4 = 5\nBob Turn\n        [1 4]\n        B = 4 = 4\nResult\n          A = 13 + 5 = 18\n        - B = 8  + 4 = 12\n        ------------------\n                       6\n\n        ---> 13 - 8 + 5 - 4    = 6\n        can also be written as:\n        ---> 13 -(8 - (5-(4)))\n             13 - 8 + (5-(4)) \n             13 - 8 + 5 - 4    = 6\nSo in recursive approach we will just keep subtracting the next Call\n```\n# Recursive Approach\n<!-- Describe your approach to solving the problem. -->\n```\ndef stoneGameVII(self, nums: List[int]) -> int:\n    def f(start,end,total):\n        if start>=end:return 0 //in recursion this line is not req. but converting this recursion to tabulation this is required\n        if total == 0:\n            return 0\n        pickS = (total-nums[start]) - f(start+1,end,total-nums[start])\n        pickE = (total-nums[end]) - f(start,end-1,total-nums[end])\n\n        return max(pickS,pickE)\n    return f(0,len(nums)-1,sum(nums))\n\n```\n\n# Memoization\n```\ndef stoneGameVII(self, nums: List[int]) -> int:\n    def f(start,end,total,dp):\n        if start>=end:return 0\n        if total == 0:\n            return 0\n        if dp[start][end][total] != -1:return dp[start][end][total]\n        pickS = (total-nums[start]) - f(start+1,end,total-nums[start],dp)\n        pickE = (total-nums[end]) - f(start,end-1,total-nums[end],dp)\n\n        dp[start][end][total] = max(pickS,pickE)\n        return dp[start][end][total]\n\n    n = len(nums)\n    t = sum(nums)\n    dp = [[[0]*(t+1) for _ in range(n+1)] for _ in range(n+1)]\n    return f(0,n-1,t,dp)\n```\n\n# Tabulation\n```\nclass Solution:\n    def stoneGameVII(self, nums: List[int]) -> int:\n        n = len(nums)\n        total = sum(nums)\n        dp = [[0]*(n+1) for _ in range(n+1)]\n        front = [0]*(n+1)\n        back =  [0]*(n+1)\n        front[1] = nums[0]\n        back[n-1] = nums[n-1]\n        # Sum from start to end and end to start\n        for i in range(1,n):\n            front[i+1] = front[i] + nums[i]\n            back[n-1-i] = back[n-i] + nums[n-i-1]\n        # note front[0] = 0\n        #      back[n]  = 0\n        # for calculation purpose\n        for start in range(n-1,-1,-1):\n            for end in range(start+1,n,1):\n                pickS = (total-(front[start+1]+back[end+1])) - dp[start+1][end]\n                pickE =  (total-(front[start]+back[end]))- dp[start][end-1]\n                dp[start][end] = max(pickS,pickE)\n        return dp[0][n-1]\n\n```
['Dynamic Programming', 'Recursion', 'Memoization', 'Python3']