讨论 / 我擦,疯了,为什么样例输出就和它不一样,而且没找到错
cszqwe 2012-05-26 08:20:00
点我顶贴 收藏 删除
program da;

const

mark:array[1..9,1..9] 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 h,l,a:array[1..9,1..9]of longint;

i,j,n,m,k,o,p,t,maxn:longint;

d1,d2:array[1..9]of longint;

function pd:boolean;

var i,j:longint;

b:array[1..9]of longint;

begin

fillchar(b,sizeof(b),0);

for i:=1 to 9 do

b[a[i,i]]:=1;

for i:=1 to 9 do if b[i]=0 then exit(false);

for i:=1 to 9 do

b[a[i,9-i+1]]:=0;

for i:=1 to 9 do if b[i]=1 then exit(false);

exit(true);

end;

procedure try(x,y,max:longint);

var j:longint;

begin

inc(t);

if t>=1400000 then

begin

writeln(maxn);

halt;

end;

if x=8 then

begin

y:=y;

end;

if a[x,y]<>0 then

begin

max:=max+a[x,y]*mark[x,y];

if (x=1)and(y=1) then

begin

if (maxn<max) then

maxn:=max;

exit;

end;

if y=1 then try(x-1,9,max) else try(x,y-1,max);

max:=max-a[x,y]*mark[x,y];

end else begin

for j:=9 downto 1 do

if ((h[x,j]=0)and(l[y,j]=0))and(a[x,y]=0) then

begin

h[x,j]:=1;

l[y,j]:=1;

a[x,y]:=j;

max:=max+j*mark[x,y];

if (x=1)and(y=1) then

begin

if (maxn<max) then maxn:=max;

exit;

end;

if y=1 then try(x-1,9,max) else try(x,y-1,max);

h[x,j]:=0;

l[y,j]:=0;

a[x,y]:=0; if x=y then d1[j]:=0;

if x=9-y+1 then d2[j]:=0;

max:=max-j*mark[x,y];

end; end;

end;

begin

for i:=1 to 9 do

for j:=1 to 9 do

begin

read(a[i,j]);

if a[i,j]<>0 then begin h[i,a[i,j]]:=1;l[j,a[i,j]]:=1;end;

end;

try(9,9,0);

writeln(-1);

end.

#1 yangyawei@2012-05-26 08:20:00
回复 删除
是所有格子数乘分值的总和,不是仅的总和
查看更多回复
提交回复