[Python3] Game Theory + Dynamic Programming - Simple Solution
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nclass Solution:\n    def stoneGameVII(self, stones: List[int]) -> int:\n        n = len(stones)\n        ps = [0] + list(accumulate(stones))\n        ops = [max, min]\n        sign = [1, -1]\n        \n        @cache\n        def dp(i: int, j: int) -> int:\n            if i == j: return 0\n            player = (i + n - j - 1) % 2\n            return ops[player](\n                sign[player] * (ps[j + 1] - ps[i + 1]) + dp(i + 1, j),\n                sign[player] * (ps[j] - ps[i]) + dp(i, j - 1)\n            )\n        return dp(0, n - 1)\n```\n\n##### 2. Bottom-Up\n\n```python3 []\nn = len(stones)\n        preSum = [0] * (n + 1)\n        for i in range(n): preSum[i + 1] = preSum[i] + stones[i]\n\n        def getSum(left, right):\n            return preSum[right + 1] - preSum[left]\n\n        dp = [[0] * n for _ in range(n)]\n        for l in range(n - 1, -1, -1):\n            for r in range(l + 1, n):\n                scoreRemoveLeftMost = getSum(l + 1, r)\n                scoreRemoveRightMost = getSum(l, r - 1)\n                dp[l][r] = max(scoreRemoveLeftMost - dp[l + 1][r], scoreRemoveRightMost - dp[l][r - 1])\n        return dp[0][n - 1]\n```
['Array', 'Math', 'Dynamic Programming', 'Game Theory', 'Python3']