project euler problem 15(错误原因,溢出。该题可以用二项式系数公式算出结果)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

// Routes.cpp : Defines the entry point for the console application.

//

#include

 

 

"stdafx.h"

#include

 

 

<iostream>

#include

 

 

<queue>

using

 

 

namespace

std;

int

 

 

grid[22][22];

class

 

 

Point

{

public

 

 

:

 

 

int

x;

 

 

int

y;

Point(

 

int x, int

y):x(x),y(y)

{}

Point(){}

};

int

 

 

count( int indexX, int

indexY)

{

memset(grid,0,

 

sizeof

(grid));

queue<Point> q;

q.push(Point(0,0));

grid[0][0] = 1;

Point temp;

 

 

do

{

temp = q.front();

q.pop();

 

 

if

(temp.x < indexX)

{

 

 

if

(grid[temp.y][temp.x +1] == 0)

{

q.push(Point(temp.x + 1,temp.y));

}

grid[temp.y][temp.x + 1] += grid[temp.y][temp.x];

 

}

 

 

if

(temp.y < indexY)

{

 

 

if

(grid[temp.y + 1][temp.x ] == 0)

{

q.push(Point(temp.x,temp.y + 1));

}

grid[temp.y + 1][temp.x] += grid[temp.y][temp.x];

 

}

}

 

while

(!q.empty());

 

 

 

return

grid[indexY][indexX];

}

int

 

 

_tmain( int

argc, _TCHAR* argv[])

{

 

 

//cout << count(1,1) << endl;

cout <<

 

" 2 * 2 "

<< count(2,2) << endl;

cout << count(3,3) << endl;

cout << count(20,20) << endl;

system(

 

"pause"

);

 

 

return

0;

}

//答案不正确,不知道什么原因

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值