首页 > 编程语言 > 详细

欧拉计划(python) problem 15

时间:2015-01-27 13:23:01      阅读:299      评论:0      收藏:0      [点我收藏+]

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?


Answer:
137846528820
Completed on Tue, 27 Jan 2015, 03:57

python code :

dict={}
def func(i,j):
    rest=dict.get(str(i)+‘_‘+str(j))
    if rest!=None:
        return rest
    else:
        if i==0 and j==0:
            return 0
        if i==0 or j==0:
            return 1
        temp=func(i-1,j)+func(i,j-1)
        dict[str(i)+‘_‘+str(j)]=temp
        return temp

result=func(20,20)
print(result)


time : <1s

欧拉计划(python) problem 15

原文:http://blog.csdn.net/zhangzhengyi03539/article/details/43193087

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!