i,j,k,t:longint;
ch:char;
a,b:array [1..9,1..9] of longint;
function almostover:boolean;
var
i,j,s:longint;
begin
s:=0;
for i:=1 to 9 do
for j:=1 to 9 do if b[i,j]=0 then inc(s);
if s=1 then exit(true) else exit(false);
end;
function check(x,y,i:longint):boolean;
var
j,k:longint;
begin
for j:=1 to 9 do if b[x,j]=i then exit(false);
for j:=1 to 9 do if b[j,y]=i then exit(false);
for j:=((x-1) div 3)*3+1 to ((x-1) div 3)*3+3 do
for k:=((y-1) div 3)*3+1 to ((y-1) div 3)*3+3 do if b[j,k]=i then exit(false);
exit(true);
end;
function calculate:longint;
var
s:longint;
begin
s:=0;
for i:=1 to 9 do
for j:=1 to 9 do
if (i=1) or (i=9) or (j=1) or (j=9) then s:=s+6*b[i,j]
else if (i=2) or (i=8) or (j=2) or (j=8) then s:=s+7*b[i,j]
else if (i=3) or (i=7) or (j=3) or (j=7) then s:=s+8*b[i,j]
else if (i=4) or (i=6) or (j=4) or (j=6) then s:=s+9*b[i,j]
else s:=s+10*b[i,j];
calculate:=s;
end;
procedure dfs(x,y:longint);
var
i,j:longint;
f:boolean;
begin
for i:=1 to 9 do
if check(x,y,i) then begin
if almostover then begin
b[x,y]:=i;
if t<calculate then t:=calculate;
b[x,y]:=0;
exit;
end;
f:=true;
for j:=9 downto 1 do
for k:=9 downto 1 do
if (((j<x) or ((j=x) and (k<y))) and (b[j,k]=0) and f) then begin
b[x,y]:=i;
dfs(j,k);
b[x,y]:=0;
f:=false;
end;
end;
end;
begin
for i:=1 to 9 do begin
for j:=1 to 9 do read(a[i,j]);
readln;
end;
b:=a;
for i:=9 downto 1 do
for j:=9 downto 1 do
if a[i,j]=0 then begin
dfs(i,j);
if t<>0 then writeln(t) else writeln(-1);
readln;
halt;
end;
end.
状态: Unaccepted
测评机: Xeost[5]
得分: 50分
提交日期: 2010-9-22 22:38:00
有效耗时: 4593毫秒
测试结果1: 通过本测试点|有效耗时203ms
测试结果2: 通过本测试点|有效耗时1047ms
测试结果3: 通过本测试点|有效耗时218ms
测试结果4: 通过本测试点|有效耗时188ms
测试结果5: 通过本测试点|有效耗时1437ms
测试结果6: 通过本测试点|有效耗时188ms
测试结果7: 通过本测试点|有效耗时250ms
测试结果8: 通过本测试点|有效耗时453ms
测试结果9: 通过本测试点|有效耗时391ms
测试结果10: 通过本测试点|有效耗时218ms
测试结果11: 选手程序运行超过时限
测试结果12: 测试结果错误.错误结果为:2864
正确结果应为:2879
测试结果13: 测试结果错误.错误结果为:2864
正确结果应为:2872
测试结果14: 测试结果错误.错误结果为:2864
正确结果应为:2860
测试结果15: 测试结果错误.错误结果为:2864
正确结果应为:2868
测试结果16: 选手程序运行超过时限
测试结果17: 测试结果错误.错误结果为:2864
正确结果应为:2856
测试结果18: 测试结果错误.错误结果为:2864
正确结果应为:2878
测试结果19: 选手程序运行超过时限
测试结果20: 测试结果错误.错误结果为:2864
正确结果应为:2876