uses crt;
var fi,fo:text;
n,m,i,j:integer;
a,b:array[-1..200,-1..200] of int64;
procedure taotep;
begin
assign(fi,'ChiPhi.inp');
{$I-} reset(fi); {$I+}
if ioresult<>0 then
begin
rewrite(fi);
reset(fi);
end;
readln(fi,n,m);
for i:=1 to n do
begin
for j:=1 to m do read(fi,a[i,j]);
readln(fi);
end;
close(fi);
end;
function min(x,y:int64):int64;
begin
min:=x;
if y<x then min:=y;
end;
procedure taomang;
begin
b[1,1]:=a[1,1];
for i:=0 to n do b[i,0]:=999999999;
for j:=0 to m do b[0,j]:=999999999;
for j:=1 to m do
for i:=1 to n do
if (i<>1) or (j<>1) then
b[i,j]:=min(b[i-1,j],b[i,j-1])*a[i,j];
end;
procedure truyvet(i,j:integer);
begin
if (i>1) or (j>1) then
begin
if b[i-1,j]=min(b[i-1,j],b[i,j-1]) then truyvet(i-1,j)
else truyvet(i,j-1);
end;
write(a[i,j],' ');
end;
BEGIN
clrscr;
taotep; taomang;
writeln('Chi phi toi thieu la:',b[n,m]);
write('Duong di la:');
truyvet(n,m);
readln
END.
Mình dùng cách quy hoạch động, dữ liệu vào ở tệp 'ChiPhi.inp', kết quả ghi ra màn hình.
Chúc bạn học tốt.
Cho mik xin ctlhn.