var f:array [0..9,0..5] of longint;
i,j,k,a,b,sum,ans:longint;
s:string;
procedure search(x,y,l,k1:longint);
begin
if (k1<0)or(x<0)or(y<0)or(x>9)or(y>5) then exit;
if f[x,y]=1 then
begin
f[x,y]:=0;
if ans<=l then ans:=l+1;
search(x+1,y,l+1,k1-1);
search(x-1,y,l+1,k1-1);
search(x,y-1,l+1,k1-1);
f[x,y]:=1;
end else
begin
search(x+1,y,l,k1-1);
search(x-1,y,l,k1-1);
search(x,y-1,l,k1-1);
end;
end;
procedure init;
begin
readln(k);
for i:=1 to 5 do
begin
readln(s);
for j:=1 to 9 do
case s[j] of
'*':f[j,i]:=0;
'K':f[j,i]:=1;
'L':begin f[j,i]:=0; a:=j; b:=i; end;
end;
end; sum:=0;
end;
procedure main;
begin
for i:=1 to a do
for j:=1 to 9 do
if f[j,i]=1 then inc(sum);
if (sum=0)or(k>a+b*9) then writeln(sum) else
begin
ans:=-maxint;
search(a,b,0,k);
writeln(ans);
end;
end;
begin
while not eof do
begin init; main; end;
end.
提交日期: 2010-10-2 8:43:00
有效耗时: 1516毫秒
测试结果1: 通过本测试点|有效耗时172ms
测试结果2: 通过本测试点|有效耗时47ms
测试结果3: 通过本测试点|有效耗时47ms
测试结果4: 测试结果错误.错误结果为:68
正确结果应为:44
测试结果5: 通过本测试点|有效耗时47ms
测试结果6: 测试结果错误.错误结果为:36
正确结果应为:0
测试结果7: 通过本测试点|有效耗时47ms
测试结果8: 通过本测试点|有效耗时47ms
测试结果9: 测试结果错误.错误结果为:44
正确结果应为:26
测试结果10: 测试结果错误.错误结果为:26
正确结果应为:8
测试结果11: 通过本测试点|有效耗时47ms
测试结果12: 通过本测试点|有效耗时47ms
测试结果13: 通过本测试点|有效耗时47ms
测试结果14: 通过本测试点|有效耗时640ms
测试结果15: 通过本测试点|有效耗时47ms
测试结果16: 通过本测试点|有效耗时94ms
测试结果17: 通过本测试点|有效耗时47ms
测试结果18: 通过本测试点|有效耗时47ms
测试结果19: 通过本测试点|有效耗时46ms
测试结果20: 通过本测试点|有效耗时47ms