Advertisement
huyhung94

Giải thuật Tám Hậu

Dec 1st, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.50 KB | None | 0 0
  1. program tam_hau;
  2. Procedure Try(j);
  3.   begin  
  4.     For i:=1 to 8 do
  5.         If (a[i] and b[i+j] and c[i-j]) then       
  6.             begin
  7.                 {đặt quân hậu}
  8.                 x[i]:=i;   a[i]:=false; b[i+j]=false; c[i-j]=false;
  9.                 If i<8 then try(j+1)
  10.                 else {in quân hậu}
  11.                     for k:=1 to n do write(x[k]:5);
  12.                 {cất quân hậu}
  13.                 a[i]:=true; b[i+j]=true; c[i-j]=true;
  14.             end;
  15.   end;
  16. BEGIN
  17.     for i:=1 to 8 do a[i]:=true;
  18.     for i:=2 to 16 do b[i+j]:=true;
  19.     for i:=-7 to 7 do c[i-j]:=true;
  20.     Try(1);
  21.     readln
  22. END.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement