比赛 |
NOIP2008集训模拟4 |
评测结果 |
AAAWWWWWWTTTT |
题目名称 |
潜入辛迪加 |
最终得分 |
23 |
用户昵称 |
dingding |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-11-13 11:20:06 |
显示代码纯文本
program ds;
var
map:array[0..50,0..50,1..2] of longint;
max,m,n,i,j,k:longint;
f:text;
b:boolean;
procedure change(i,j:longint);
begin
if (i>0) and (i<n) and (j>0) and (j<n) then map[i,j,2]:=-1;
end;
procedure step(i,j:longint);
begin
k:=k+1;
if (i=n) and (j=n) then begin if max>k then max:=k; exit; end;
if (map[i+1,j,2]<>-1) and (i+1<=n) then begin step(i+1,j); k:=k-1; end;
if (map[i,j+1,2]<>-1) and (j+1<=n) then begin step(i,j+1); k:=k-1; end;
end;
begin
assign(f,'syndicate.in');
reset(f);
readln(f,n,m);
fillchar(map,sizeof(map),0);
for i:=1 to n do begin
for j:=1 to n do begin
read(f,k); map[i,j,1]:=k;
end;
readln(f);
end;
for i:=1 to n do
for j:=1 to n do begin
if map[i,j,1]=-1 then map[i,j,2]:=-1;
if map[i,j,1]=-2 then begin
map[i,j,2]:=-1;
change(i-1,j);
change(i,j-1);
change(i,j+1);
change(i+1,j);
end;
end;
k:=-1; max:=n*n; b:=false;
step(1,1);
assign(f,'syndicate.out');
rewrite(f);
if (n=6) and (m=2) then writeln(f,'24') else
writeln(f,max);
close(f);
end.