Giúp em chữa bài mã đi tuần bằng code pascal ạ. Em làm mãi, nhập n = 4
thì lại không ra.
Const max=200;
Fi='QUANMA.INP';
Fo='QUANMA.OUT';
Hx:Array[1..8] of integer=(2,1,-1,-2,-2,-1,1,2);
Hy:Array[1..8] of integer=(1,2,2,1,-1,-2,-2,-1);
Var
Dd : Array[1..Max,1..max] of integer;
n, x, y, dem :integer;
Procedure readf;
Begin
Assign (input,fi);
Reset (input);
Readln (n,x,y);
close (input);
fillchar (dd,sizeof(dd),0);
dd[x,y]:=1;
end;
Procedure print;
Var i,j:longint;
Begin
inc(dem);
Writeln ('Nghiem thu ',dem,' la : ');
For i :=1 to n do
Begin
For j :=1 to n do
Write (dd[i,j],#32);
Writeln;
end;
end;
procedure tim(i:longint);
Var j,u,v:longint;
Begin
For j :=1 to 8 do
Begin
u:=x+hx[j];
v:=y+hy[j];
If (u>=1) and (u<=n) and (v>=1) and (v<=n) then
If dd[u,v] =0 then
Begin
x:=u;
y:=v;
dd[u,v]:=i;
If i =n*n then print
else tim(i+1);
x:=x-hx[j];
y:=y-hy[j];
dd[u,v]:=0;
END;
end;
end;
BEGIN
readf;
Assign (output,fo);
Rewrite (output);
tim(2);
Close (output);
end.