DP-LeetCode62. 不同路径
程序员文章站
2022-03-24 20:49:15
...
1、题目描述
https://leetcode-cn.com/problems/unique-paths/
2、代码详解
转移方程
初始条件和边界情况
计算顺序
class Solution(object):
def uniquePaths(self, m, n):
dp = [[1]*n for _ in range(m)] # m * n
for i in range(m):
for j in range(n):
if i == 0 or j == 0: # 第一行和第一列只有1种走法
dp[i][j] = 1
continue # 跳出循环
dp[i][j] = dp[i-1][j] + dp[i][j-1]
return dp[m-1][n-1]
m = 7
n = 3
s = Solution()
print(s.uniquePaths(m, n))
上一篇: 增加行星轮减速后机械臂调试