主题:[求助]usaco c1.4 checker 帮者必加分!
就是n皇后问题
我编的是
var
s:array[1..14]of integer;
a,b,c:array[-14..28]of boolean;
i,j,k,l,m,n,sum:integer;
procedure serch(m:integer);
var
i:integer;
begin
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;
begin
assign(input,'checker.in');reset(input);
assign(output,'checker.out');rewrite(output);
readln(n);sum:=0;
for i:=-14 to 14 do
begin a[i]:=true;b[i]:=true;c[i]:=true; end;
serch(1);
writeln(sum);
close(input);close(output);
end.
谁能帮忙改一下错?谢谢!
我编的是
var
s:array[1..14]of integer;
a,b,c:array[-14..28]of boolean;
i,j,k,l,m,n,sum:integer;
procedure serch(m:integer);
var
i:integer;
begin
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;
begin
assign(input,'checker.in');reset(input);
assign(output,'checker.out');rewrite(output);
readln(n);sum:=0;
for i:=-14 to 14 do
begin a[i]:=true;b[i]:=true;c[i]:=true; end;
serch(1);
writeln(sum);
close(input);close(output);
end.
谁能帮忙改一下错?谢谢!