问题:

Starting in thetop left corner of a 2×2 grid, and only being able to move to the right anddown, there are exactly 6 routes to the bottom right corner.

网格路线问题_路线个数

How many suchroutes are there through a 20×20 grid?

解决思路:

 网格路线问题_网格_02

网格路线问题_网格_03

网格路线问题_路线个数_04

 

将上图数据放正,就是杨辉三角:

前十行如下:










1


















1


1
















1


2


1














1


3


3


1












1


4


6


4


1










1


5


10


10


5


1








1


6


15


20


15


6


1






1


7


21


35


35


21


7


1




1


8


28


56


70


56


28


8


1


1


9


36


84


126


126


84


36


9


1

 

11 行:

1104512021025221012045101

12 行:

1115516533046246233016555111

13行:

1126622049579292479249522066121

14行:

11378286715128717161716128771528678131

……

n-1行:

1,(n-1C1,(n-2C2,(n-1Cr-1),,(n-1Cn-2),1

n行:

1nC1nC2nCr-1),nCrnCr-1),1

 

问题要求的20*20的网格的路径数目,即杨辉三角第41行第21个数。

利用杨辉三角的性质:

n行的m个数可表示为C(n-1,m-1),即为从n-1个不同元素中取m-1个元素的组合数。

组合数计算方法:C(n,m)=n!/[m!(n-m)!]

可计算第41行,第21个数为:C(40,20)=40!/[20!*20!]=137846528820