Lattice paths
Problem 15
Starting in the top left corner of a 2×2 grid, and only being able to move to the right and down, there are exactly 6 routes to the bottom right corner.

How many such routes are there through a 20×20 grid?
这个只要从上到下,一个一个加就好了,非常简单。
def routes():
grid = [[0] * 21] * 21
for i in range(0,21):
grid[0][i] = 1
grid[i][0] = 1
for i in range(1,21):
for j in range(1,21):
grid[i][j] = grid[i][j-1] + grid[i-1][j]
return grid[20][20]
print(routes())
本文探讨了一个经典的组合数学问题:在一个20x20的网格中,仅能向右或向下移动,从左上角到达右下角的不同路径数量。通过构建二维数组并使用动态规划的方法,实现了路径计数的高效计算。
148

被折叠的 条评论
为什么被折叠?



