动态规划
Posted topass123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动态规划相关的知识,希望对你有一定的参考价值。
class Solution: def maxValue(self, grid: List[List[int]]) -> int: for i in range(len(grid)): for j in range(len(grid[0])): if i == 0 and j == 0: continue elif i == 0: grid[i][j] += grid[i][j-1] elif j == 0: grid[i][j] += grid[i-1][j] else: grid[i][j] += max(grid[i-1][j],grid[i][j-1]) return grid[-1][-1]
class Solution: def maxValue(self, grid: List[List[int]]) -> int: if not grid or not grid[0]: return 0 m, n = len(grid), len(grid[0]) for i in range(1, n): grid[0][i] += grid[0][i-1] for i in range(1, m): grid[i][0] += grid[i-1][0] for j in range(1,n): grid[i][j] += max(grid[i-1][j], grid[i][j-1]) return grid[-1][-1] 作者:luanz 链接:https://leetcode-cn.com/problems/li-wu-de-zui-da-jie-zhi-lcof/solution/pythonchang-gui-dong-gui-jie-fa-jian-dan-yi-dong-b/ 来源:力扣(LeetCode) 著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
以上是关于动态规划的主要内容,如果未能解决你的问题,请参考以下文章