讨论 / 过河卒的一个奇怪的问题
曹哲睿 2013-08-11 21:45:00
点我顶贴 收藏 删除
请问一下,我的代码为什么最后会输出一些负数,而有时候确实正确的答案啊

program aa;

var n,m,p,q,i,j:longint;

map:array[-2..20,-2..20] of boolean;

f:array[0..20,0..20] of longint;

begin

read(n,m);

read(p,q);

fillchar(map,sizeof(map),false);

fillchar(f,sizeof(f),0);

map[p,q]:=true;

map[p-1,q-2]:=true;

map[p-1,q+2]:=true;

map[p+1,q-2]:=true;

map[p+1,q+2]:=true;

map[p-2,q-1]:=true;

map[p-2,q+1]:=true;

map[p+2,q-1]:=true;

map[p+2,q+1]:=true;

for i:=0 to n do

for j:=0 to n do

begin

if map[i,j]=true then f[i,j]:=0

else begin

if (i=0) and (j=0) then f[i,j]:=1 ;

if (i=0) and (j<>0) then f[i,j]:=f[i,j-1];

if (i<>0) and (j=0) then f[i,j]:=f[i-1,j];

if (i<>0) and (j<>0) then f[i,j]:=f[i-1,j]+f[i,j-1];

end;

end;

writeln(f[n,m]);

end.

#1 Hlog@2011-08-10 02:11:00
回复 删除
因为数据范围开小了,longint不够,要用int64

最后的结果都是几亿几十亿的

#2 y1h2d3@2011-08-10 22:10:00
回复 删除
同ls
#3 余洋go@2012-07-11 23:12:00
回复 删除
数据范围小了,改成int64即可;

n<=25,m<=25,map下标小了;

循环处有问题, for i:=0 to n do

for j:=0 to n (m) do.

#4 9033@2012-07-12 01:36:00
回复 删除
数据范围小了
#5 殇樱@2013-08-11 21:45:00
回复 删除
我知道

你前面都对的,后面有些麻烦:

e[0,-1]:=1;

for i:=0 to a do

for j:=0 to b do

if f[i,j]=false then e[i,j]:=e[i-1,j]+e[i,j-1];

writeln(e[a,b]);

改下吧~亲~

查看更多回复
提交回复