Python (Simple DP)
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```\nclass Solution:\n    def maxScore(self, grid):\n        m, n = len(grid), len(grid[0])\n\n        @lru_cache(None)\n        def dfs(i,j):\n            if i >= m or j >= n:\n                return 0 \n\n            max_val = float("-inf")\n\n            if i+1 < m:\n                max_val = max(max_val,grid[i+1][j]-grid[i][j]+dfs(i+1,j))\n\n            if j+1 < n:\n                max_val = max(max_val,grid[i][j+1]-grid[i][j]+dfs(i,j+1))\n\n            return max(0,max_val)\n\n        mx_val, mx_val1 = float("-inf"), float("-inf")\n\n        for i in range(m):\n            for j in range(n):\n                mx_val = max(mx_val,dfs(i,j))\n                if (i+1 < m):\n                    mx_val1 = max(mx_val1,grid[i+1][j]-grid[i][j])\n                if (j+1 < n):\n                    mx_val1 = max(mx_val1,grid[i][j+1]-grid[i][j])\n\n        if mx_val == 0:\n            return mx_val1\n\n        return mx_val \n```
['Python3']