测评机: Xeond[6]
得分: 65分
提交日期: 2010-10-2 13:20:00
有效耗时: 1032毫秒
测试结果1: 通过本测试点|有效耗时156ms
测试结果2: 通过本测试点|有效耗时47ms
测试结果3: 通过本测试点|有效耗时47ms
测试结果4: 选手程序运行超过时限
测试结果5: 测试结果错误.错误结果为:2
正确结果应为:0
测试结果6: 测试结果错误.错误结果为:2
正确结果应为:0
测试结果7: 测试结果错误.错误结果为:2
正确结果应为:10
测试结果8: 通过本测试点|有效耗时63ms
测试结果9: 选手程序运行超过时限
测试结果10: 测试结果错误.错误结果为:11
正确结果应为:8
测试结果11: 测试结果错误.错误结果为:11
正确结果应为:4
测试结果12: 通过本测试点|有效耗时47ms
测试结果13: 通过本测试点|有效耗时47ms
测试结果14: 通过本测试点|有效耗时312ms
测试结果15: 通过本测试点|有效耗时47ms
测试结果16: 通过本测试点|有效耗时78ms
测试结果17: 通过本测试点|有效耗时47ms
测试结果18: 通过本测试点|有效耗时47ms
测试结果19: 通过本测试点|有效耗时47ms
测试结果20: 通过本测试点|有效耗时47ms
var
a:array[0..11,0..11] of longint;
i,j,k,l,m,n,x,y,ahe,ans:longint;
ch:char;
procedure search(x,y,he,step:longint);
var
i,j,l,m,x1,y1:longint;
begin
if step<0 then exit;
if (x<0) or (x>9) or (y<0) or (y>5) then exit;
if a[x,y]=1 then
begin
a[x,y]:=0;
if he>=ans then ans:=he+1;
search(x+1,y,he+1,step-1);
search(x-1,y,he+1,step-1);
search(x,y-1,he+1,step-1);
a[x,y]:=1;
end
else
begin
search(x+1,y,he,step-1);
search(x-1,y,he,step-1);
search(x,y-1,he,step-1);
end;
end;
begin
while not eof do
begin
ans:=0;
readln(k);
for i:=1 to 5 do
begin
for j:=1 to 9 do
begin
read(ch);
if ch='*' then a[j,i]:=0;
if ch='K' then begin a[j,i]:=1;inc(ahe);end;
if ch='L' then
begin
x:=i;
y:=j;
a[j,i]:=0;
end;
end;
readln;
end;
if (ahe=0) then begin writeln('0');end
else
begin
search(y,x,0,k);
writeln(ans);
end;
end;
end.
var
a:array[1..5,1..9] of integer;
s:string;
n,t,tot,max,i,j,x,y:integer;
procedure find(x,y,k:integer);
var c:integer;
begin
if t=tot then begin writeln(t);halt;end;
if k>n then begin if t>max then max:=t;exit;end;
if y>1 then
begin
c:=0;
if a[x,y-1]=1 then begin a[x,y-1]:=0;inc(t);c:=1;end;
find(x,y-1,k+1);
if c=1 then begin a[x,y-1]:=1;dec(t);end;
end;
if y<9 then
begin
c:=0;
if a[x,y+1]=1 then begin a[x,y+1]:=0;inc(t);c:=1;end;
find(x,y+1,k+1);
if c=1 then begin a[x,y+1]:=1;dec(t);end;
end;
if x>1 then
begin
c:=0;
if a[x-1,y]=1 then begin a[x-1,y]:=0;inc(t);c:=1;end;
find(x-1,y,k+1);
if c=1 then begin a[x-1,y]:=1;dec(t);end;
end;
end;
begin
readln(n);
for i:=1 to 5 do
begin
readln(s);
for j:=1 to 9 do
begin
if s[j]='K' then a[i,j]:=1;
if s[j]='L' then begin x:=i;y:=j;end;
end;
end;
for i:=1 to x do
for j:=1 to 9 do
if a[i,j]=1 then inc(tot);
if n>45 then begin write(tot);halt;end;
find(x,y,1);
writeln(max);
end.