文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Project Euler Problem 15

Project Euler Problem 15

时间:2011-03-11  来源:Ray Z

Starting in the top left corner of a 22 grid, there are 6 routes (without backtracking) to the bottom right corner.

How many routes are there through a 2020 grid?

 1 #include <iostream>
 2 using namespace std;
 3 
 4 #define num 41
 5 long long PascalTriangle[num][num];
 6 
 7 void CalcPascalTriangle()
 8 {
 9     PascalTriangle[0][0] = 1;
10     PascalTriangle[1][0] = 1;
11     PascalTriangle[1][1] = 1;
12     for(int i=2; i<num; i++)
13     {
14         for(int j=0; j<=i; j++)
15         {
16             if(j == 0 || j == i)
17             {
18                 PascalTriangle[i][j] = 1;
19             }
20             else
21             {
22                 PascalTriangle[i][j] = PascalTriangle[i-1][j-1] + PascalTriangle[i-1][j];
23             }
24         }
25     }
26 }
27 
28 int main()
29 {
30     CalcPascalTriangle();
31     cout << PascalTriangle[40][20];
32     cin.get();
33 }

 

排行榜 更多 +
宝宝情商养成宝宝巴士

宝宝情商养成宝宝巴士

休闲益智 下载
燥热手机版

燥热手机版

飞行射击 下载
巨人狙击手安卓版

巨人狙击手安卓版

飞行射击 下载