首页 > 其他 > 详细

Project Euler 15 solution

时间:2016-07-20 16:13:26      阅读:357      评论: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?

Link: https://projecteuler.net/problem=15 

My solution:

Using recursie function to find out the routes.

Implemented by Lu.Qian. using C++:

 1 #include <iostream>
 2 //#include <cstring>
 3 //#include <cmath>
 4 //#include <map>
 5 using namespace std;
 6 
 7 unsigned long long int num = 0;
 8 void find_route(int len, int wid){
 9     if(len == 0 || wid == 0){
10         num++;
11     }
12     find_route(len - 1, wid);
13     find_route(len, wid - 1);
14 }
15 
16 int main()
17 {
18     
19     find_route(20,20);
20     cout<<num<<endl;
21     return 0;    
22 }

However, this project I worte will take so much cost on recurive funciton, and the running time it take will be unacceptable.

So I‘ll wirite another function by using simple iteration. 

 

Project Euler 15 solution

原文:http://www.cnblogs.com/QianL/p/5688720.html

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