讨论 / 这道题测试数据是不是有问题呀 不然我做的不对?!
yangzhe 2010-07-18 01:27:00
点我顶贴 收藏 删除
const

dx:array [1..2] of integer=(0,1);

dy:array [1..2] of integer=(1,0);

var

total:longint;

a:array [0..21,0..21] of 0..1;

i,j,n:integer;

function check(p,q:integer):boolean;

begin

if (p in [1..n])and(q in [1..n])and(a[p,q]=0) then exit(true)

else exit(false)

end;

procedure work(x,y:integer);

var i:integer;

begin

if (x=n)and(y=n) then begin

inc(total);

exit

end;

for i:=1 to 2 do

if check(x+dx[i],y+dy[i]) then begin

a[x+dx[i],y+dy[i]]:=1;

work(x+dx[i],y+dy[i]);

a[x+dx[i],y+dy[i]]:=0

end;

end;

begin

total:=0;

readln(n);

for i:=1 to n do begin

for j:=1 to n do

read(a[i,j]);

readln

end;

work(1,1);

write(total);

end.

第9数据超时,第10个输出过多

#1 艾嘉@2010-07-18 01:27:00
回复 删除
用记忆化搜索, 一开始判断g[1,1]是否为障碍物,是输出0,不是做搜索
查看更多回复
提交回复