比赛 暑假培训B班二测 评测结果 AAAAAA
题目名称 返回住所 最终得分 100
用户昵称 Fangel 运行时间 0.002 s
代码语言 Pascal 内存使用 0.17 MiB
提交时间 2012-07-22 10:43:59
显示代码纯文本
var
a,b,c,d,r,k,sum:longint;
ss:array[1..5,1..5] of char;
path:array[1..5,1..5] of integer;
procedure cz(x,y,n:longint);
begin
if (x=1) and (y=c) and (n<=k) then inc(sum)
else if n<=k then
begin
if (y>1) and (path[x,y-1]=0) and (ss[x,y-1]<>'T') then begin path[x,y-1]:=1;cz(x,y-1,n+1);path[x,y-1]:=0;end;
if (x>1) and (path[x-1,y]=0) and (ss[x-1,y]<>'T') then begin path[x-1,y]:=1;cz(x-1,y,n+1);path[x-1,y]:=0;end;
if (y<c) and (path[x,y+1]=0) and (ss[x,y+1]<>'T') then begin path[x,y+1]:=1;cz(x,y+1,n+1);path[x,y+1]:=0;end;
if (x<r) and (path[x+1,y]=0) and (ss[x+1,y]<>'T') then begin path[x+1,y]:=1;cz(x+1,y,n+1);path[x+1,y]:=0;end;
end;
end;

begin
assign(input,'backbarn.in');
reset(input);
assign(output,'backbarn.out');
rewrite(output);
readln(r,c,k);
for a:=1 to r do
begin
for b:=1 to c do
read(ss[a,b]);
readln;
end;
path[r,1]:=1;
cz(r,1,1);
write(sum);

close(input);
close(output);
end.