Lattice paths

来源:互联网 发布:linux 增加交换空间 编辑:程序博客网 时间:2024/06/06 08:35

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())



1 0