Matrix DP
Code\n\nclass Solution:\n    def maxScore(self, grid: List[List[int]]) -> int:\n        # DP\n        # Time Complexity: O(mn)\n        # Space Complexity: O(mn
# Code\n```\nclass Solution:\n    def maxScore(self, grid: List[List[int]]) -> int:\n        # DP\n        # Time Complexity: O(mn)\n        # Space Complexity: O(mn)\n        m, n = len(grid), len(grid[0])\n        dp = [[-inf] * (n+1) for _ in range(m+1)]\n        ans = -inf\n        for i in range(1, m+1):\n            for j in range(1, n+1):\n                if i == 1 and j == 1: continue\n                if i != 1:\n                    dp[i][j] = grid[i-1][j-1] - grid[i-2][j-1] + max(0, dp[i-1][j])\n                if j != 1:\n                    dp[i][j] = max(dp[i][j], grid[i-1][j-1] - grid[i-1][j-2] + max(0, dp[i][j-1]))\n                ans = max(ans, dp[i][j])\n        return ans\n```
['Dynamic Programming', 'Python3']