Lattice paths

本文探讨了一个经典的组合数学问题:在一个20x20的网格中,仅能向右或向下移动,从左上角到达右下角的不同路径数量。通过构建二维数组并使用动态规划的方法,实现了路径计数的高效计算。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值