PASCAL植树问题

来源:百度知道 编辑:UC知道 时间:2024/05/05 19:06:06
在一个6*6的正方形种24棵树,每行每列4个

const n=3;r=2;
var a:array[1..n,1..n] of integer;
b,c:array[1..n] of integer;
total:longint;
procedure try(s,x,y:integer);
var i,j,d:integer;
begin
if s>n*r then begin
writeln('NO:',total+1);inc(total);
for i:=1 to n do begin
for j:=1 to n do if a[i,j]=1 then write('*')else write('.');
writeln;
end;
end
else for d:=y to n do begin
if (a[x,d]=0) and (b[x]<r) and (c[d]<r) then begin
a[x,d]:=1;inc(b[x]);inc(c[d]);
if s mod r=0 then try(s+1,x+1,1) else try(s+1,x,d+1);
a[x,d]:=0;dec(b[x]);dec(c[d]);
end;
end;
end;
begin
fillchar(a,sizeof(a),0);
fillchar(b,sizeof(b),0);
c:=b;
total:=0;
try(1,1,1);
writeln(total);
readln;
end.

这不是pascal可以解决的问题,
它不是万能的!!!!!!!!!!!!!!!!!!