Moshu Junior

Data inscrierii: 08/Noi/2007 Mesaje: 6 Localitate: Ploiesti
|
Trimis: 29/11/2007 10:11 Titlul subiectului: problema backtracking generalizat |
|
|
| Cod: | Type matrice=array[1..8,1..10] of byte;
sir=array[1..4] of shortint;
const lab:matrice=((0,0,0,0,0,1,0,1,0,0),(0,1,1,1,0,1,0,1,0,0),
(0,0,1,0,1,1,0,1,1,1),(0,0,1,0,1,0,1,0,0,0),
(0,0,0,1,1,0,0,0,0,0),(0,1,1,1,1,1,1,1,0,0),
(1,1,0,0,1,0,0,0,0,0),(0,0,0,0,1,0,0,0,0,0));
dx:sir=(-1,0,1,0);
dy:sir=(0,1,0,-1);
var x0,y0:byte;n,m:byte;t:matrice;
procedure scrie;
var i,j:byte;
begin
for i:=1 to 8 do
begin
for j:=1 to 10 do
write(t[i,j],' ');
writeln;
end;
writeln
end;
Procedure traseu(I,j,pas:byte);
var ii,jj:shortint; k:byte;
cond:boolean;
begin
For k:=1 to 4 do
begin
ii:=i+dx[k];
jj:=j+dy[k];
cond:=(ii in[1..n])and(jj in[1..m])and(lab[ii,jj]=1)and(t[ii,jj]=0);
if cond then begin
t[ii,jj]:=pas;
if (ii in[1,n])or(jj in[1,m]) then scrie;
traseu(ii,jj,pas+1);
t[ii,jj]:=0;
end;
end;
end;
begin
write('x0=');readln(x0);n:=8;m:=10;
write('y0=');readln(y0);
t[x0,y0]:=1;
traseu(x0,y0,2);
readln
end. |
|
|