Chinaunix首页 | 论坛 | 博客
  • 博客访问: 215662
  • 博文数量: 68
  • 博客积分: 3120
  • 博客等级: 中校
  • 技术积分: 715
  • 用 户 组: 普通用户
  • 注册时间: 2008-03-08 09:53
文章分类
文章存档

2012年(29)

2011年(3)

2010年(18)

2009年(18)

我的朋友

分类: C/C++

2012-01-18 20:39:05

问题:

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

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

答案:137846528820

类似于杨辉三角的解决方法:

#include

int main(void)
{
    long long grid[21][21] = {{0L}};

    int i=0,j=0;

    for(i=0; i<21; i++)
        grid[0][i]=grid[i][0]=1;

    for(i=1; i<21; i++)
        for(j=1; j<21; j++)
                grid[i][j] = grid[i-1][j] + grid[i][j-1];

    printf("The numbers of way is %lli\n", grid[20][20]);
    return 0;
}




阅读(606) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~