码迷,mamicode.com
首页 > 编程语言 > 详细

欧拉计划(python) problem 15

时间:2015-01-27 13:25:01      阅读:191      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!