边搜边算,第9行直接跳过(最后一行和肯定是45,值肯定是270,当然是在有解的情况下),卡时1100W,最高得分85
得分: 65分
提交日期: 2012-11-1 22:00:00
有效耗时: 11109毫秒
测评机: Xeost[5]
得分: 85分
提交日期: 2012-11-1 22:02:00
有效耗时: 17611毫秒
不卡时
得分: 50分
提交日期: 2012-11-1 21:53:00
有效耗时: 5484毫秒
卡时1000W,忽略最后一行
测评机: Xeond[6]
得分: 90分
提交日期: 2012-11-1 22:06:00
有效耗时: 19594毫秒
结论:卡时最好卡1000W左右,平均1S卡500W
另求高人指教为什么不卡时都会有WA
procedure jishuan;
var
i,j,ans:longint;
begin
ans:=0;
for i:=0 to 8 do
for j:=0 to 8 do
begin
ans:=ans+fen[i,j]*map[i,j];
end;
if ans>best then best:=ans;
end;
if (x=9) then
begin
jishuan;
exit;
end;
以上2处是最后计算
program sudoku;
const
biao:array[0..8,0..8] of longint=(
(6,6,6,6,6,6,6,6,6),
(6,7,7,7,7,7,7,7,6),
(6,7,8,8,8,8,8,7,6),
(6,7,8,9,9,9,8,7,6),
(6,7,8,9,10,9,8,7,6),
(6,7,8,9,9,9,8,7,6),
(6,7,8,8,8,8,8,7,6),
(6,7,7,7,7,7,7,7,6),
(6,6,6,6,6,6,6,6,6));
var
map:array[0..9,0..9] of longint;
hang,lie:array[0..8,1..9] of boolean;
kuai:array[0..2,0..2,1..9] of boolean;
count:longint;
ans:longint;
procedure init;
begin
end;
procedure terminate;
begin
close(input);
close(output);
halt;
end;
procedure readdata;
var
i,j:longint;
begin
for i:=0 to 8 do
for j:=0 to 8 do
begin
read(map[i,j]);
if map[i,j]<>0 then
begin
hang[i,map[i,j]]:=true;
lie[j,map[i,j]]:=true;
kuai[i div 3,j div 3,map[i,j]]:=true;
end;
end;
end;
function check(x,y,z:longint):boolean;
begin
if hang[x,z] then exit(false);
if lie[y,z] then exit(false);
if kuai[x div 3,y div 3,z] then exit(false);
exit(true);
end;
procedure dfs(x,y,z:longint);
var
newx,newy:longint;
i:longint;
begin
inc(count);
if count>10000000 then
begin
writeln(ans);
terminate;
end;
if (x=8) and (y=0) then
begin
if z+270>ans then
begin
ans:=z+270;
exit;
end;
exit;
end;
if map[x,y]<>0 then
begin
newx:=x;
newy:=y+1;
if newy=9 then
begin
newx:=newx+1;
newy:=0;
end;
dfs(newx,newy,z+map[x,y]*biao[x,y]);
exit;
end
else begin
for i:=9 downto 1 do
if check(x,y,i) then
begin
hang[x,i]:=true;
lie[y,i]:=true;
kuai[x div 3,y div 3,i]:=true;
newx:=x;
newy:=y+1;
if newy=9 then
begin
newx:=newx+1;
newy:=0;
end;
dfs(newx,newy,z+i*biao[x,y]);
hang[x,i]:=false;
lie[y,i]:=false;
kuai[x div 3,y div 3,i]:=false;
end;
end;
end;
procedure work;
begin
count:=0;
ans:=-1;
dfs(0,0,0);
writeln(ans);
end;
begin
readdata;
work;
terminate;
end.