Page 65 - C:\Users\Admin\Desktop\Sach mem upweb\
P. 65
100 Problems & Solutions Trang 65
(Dành cho học sinh THPT)
{Recommend:m,n<5}
const m=4;n=4;max=m*n;
var
a: array[1..m,1..n] of byte;
i1,j1,dem,daxep,tg: integer;
f: text;
time: longint absolute $0:$46C;
save: longint;
{------------------------------------}
procedure init;
begin
for i1:=1 to m do
for j1:=1 to n do a[i1,j1]:=0;
dem:=0; daxep:=0; tg:=0;
end;
{------------------------------------}
procedure kq;
begin
for i1:=1 to m do
begin
for j1:=1 to n do write(f,a[i1,j1],' ');
writeln(f);
end;
end;
{------------------------------------}
procedure try(i,j: integer);
var i2,j2,flag: integer;
begin
if (daxep=max) then begin kq; writeln(f); tg:=tg+1; end
else
begin
flag:=j;
while (flag
if (a[i,flag]<>0) then flag:=flag-1;
for i2:=i to m do for j2:=j to flag do
begin
dem:=dem+1;
for i1:=i to i2 do for j1:=j to j2 do a[i1,j1]:=dem;
daxep:=daxep+(i2-i+1)*(j2-j+1);
i1:=i;j1:=j2;
while (a[i1,j1]<>0) do
begin
j1:=j1+1;
if j1=n+1 then begin j1:=1; i1:=i1+1; end;
end;
try(i1,j1);
daxep:=daxep-(i2-i+1)*(j2-j+1);
for i1:=i to i2 do
for j1:=j to j2 do a[i1,j1]:=0;
Tin học & Nhà trường 100 Đề Toán - Tin học