思路:动态规划 1、i == 0,上累加 2、j == 0,左累加 3、i > 0 and j > 0,max(上,左) + 当前

class Solution:
    def maxValue(self , grid: List[List[int]]) -> int:
        # write code here
        if len(grid) == 0 or len(grid[0]) == 0:
            return 0
        
        dp = [[0]*len(grid[0]) for _ in range(len(grid))]
        dp[0][0] = grid[0][0]
        
        for i in range(len(grid)):
            for j in range(len(grid[0])):
                if i == 0 and j >= 1:
                    dp[i][j] = dp[i][j-1] + grid[i][j]
                if j == 0 and i >= 1:
                    dp[i][j] = dp[i-1][j] + grid[i][j]
                if i > 0 and j > 0:
                    dp[i][j] = max(dp[i-1][j], dp[i][j-1]) + grid[i][j]
        return dp[-1][-1]