主题:n皇后求助++分 谁帮帮我!
var
s:array[1..14]of integer;
a,b,c:array[-14..28]of boolean;
able:array[1..13,1..13]of boolean;
i,j,k,l,m,n,sum:longint;
procedure serch(m:integer);
var
i:integer;
begin
if sum=3 then exit;
if m=n+1 then begin inc(sum);
if sum<=3 then begin write(s[1]);for i:=2 to n do write(' ',s[i]);
writeln;end;
exit;
end;
for i:=1 to n do
if (a[i])and(b[m-i])and(c[m+i]) then begin
a[i]:=false;b[m-i]:=false;c[m+i]:=false;
s[m]:=i;
serch(m+1);
a[i]:=true;b[m-i]:=true;c[m+i]:=true;
end;
end;
procedure greatserch(m:integer);
var
i,k:integer;
begin
if m=n+1 then begin inc(sum);
exit;
end;
k:=n;
if m=1 then begin k:=k div 2; end;
for i:=1 to k do
if (a[i])and(b[m-i])and(c[m+i]) then begin
a[i]:=false;b[m-i]:=false;c[m+i]:=false;
greatserch(m+1);
a[i]:=true;b[m-i]:=true;c[m+i]:=true;
end;
end;
procedure superserch(m:integer);
var
i,a1,b1:integer;
begin
if m=n+1 then begin inc(sum,2);
exit;
end;
b1:=n;a1:=1;
if m=1 then begin a1:=n div 2+1; b1:=n div 2+1; end;
if m=2 then b1:=b1 div 2;
for i:=a1 to b1 do
if (a[i])and(b[m-i])and(c[m+i]) then begin
a[i]:=false;b[m-i]:=false;c[m+i]:=false;
superserch(m+1);
a[i]:=true;b[m-i]:=true;c[m+i]:=true;
end;
end;
begin
assign(input,'checker.in');reset(input);
assign(output,'checker.out');rewrite(output);
readln(n);sum:=0;
for i:=-14 to 28 do begin a[i]:=true;b[i]:=true;c[i]:=true; end;
fillchar(able,sizeof(able),true);
serch(1);
sum:=0;
for i:=-14 to 28 do begin a[i]:=true;b[i]:=true;c[i]:=true; end;
greatserch(1);
sum:=sum*2;
if n mod 2=1 then superserch(1);
writeln(sum);
close(input);close(output);
end.
是usaco的c1.4 checker
我已经等了很久了,谁帮帮我!