解题思路:
注意事项:
参考代码:
def countRoutes(m, n):
dp = [[0] * (n+1) for _ in range(m+1)]
# 初始化边界条件
for i in range(1, m+1):
dp[i][1] = 1
for j in range(1, n+1):
dp[1][j] = 1
# 计算其他位置的移动路线数目
for i in range(2, m+1):
for j in range(2, n+1):
dp[i][j] = dp[i-1][j] + dp[i][j-1]
return dp[m][n]
m, n = map(int, input().split())
print(countRoutes(m, n))
0.0分
0 人评分