2000 - BÀI TOÁN 8 HẬU (DÀNH CHO HỌC SINH TIỂU HỌC)CÓ RẤT NHIỀU...
{$A+,B-,D+,E+,F-,G-,I+,L+,N-,O-,P-,Q+,R+,S+,T-,V+,X+}
{$M 16384,0,655360}
uses crt;
const fo = 'hau.out';
n = 8;
var A : array[1..n,1..n] of byte;
c : array[1..n] of byte;
dc1 : array[2..2*n] of byte;
dc2 : array[1-n..n-1] of byte;
sn : integer;
f : text;
procedure ghino;
var i,j : byte;
begin
inc(sn);
writeln(f,'Nghiem thu ',sn,' la :');
for i := 1 to n do
begin
for j := 1 to n do
write(f,A[i,j],#32);
writeln(f);
end;
writeln(f);
end;
procedure vet(i : byte);
var j : byte;
if i = n+1 then
begin
ghino;
exit;
end;
for j := 1 to n do
if (c[j] =0)and(dc1[i+j]=0) and (dc2[i-j]=0) then
begin
A[i,j] := 1; c[j] := 1; dc1[i+j] :=1 ; dc2[i-j] := 1;
vet(i+1);
A[i,j] := 0; c[j] := 0; dc1[i+j] :=0 ; dc2[i-j] := 0;
end;
BEGIN
assign(f,fo);
rewrite(f);
vet(1);
close(f);
END.