[r]
(1)BÀI TOÁN HAY – TAM GIÁC SỐ
TGSO.INP TGSO.OUT
5 8 4
*****************
6 5
*****************
30
***************** 38
*****************
Program TAM_GIAC_SO;
{tim tong dai lon nhat xuat phat tu dinh den canh day} Const max = 100;
fi = 'E:\TGSO.INP'; fo = 'E:\TGSO.OUT';
Type Mang1 = array[1 max,1 max] of integer; Var a : Mang1;
i,j,n,s : integer;sao : string[40];f1,f2 : text; Procedure Nhap;
Begin
readln(f1,n); for i:=1 to n begin
for j:=1 to i read(f1,a[i,j]); readln(f1);
end;
readln(f1,sao); end;
Procedure Xuli; Var i,j,k:integer; Begin
b[1,1]:=a[1,1]; for i:=2 to n begin
for j:=1 to i-1 for k:=0 to
if (b[i,j+k]=0) or (b[i-1,j]+a[i,j+k] > b[i,j+k]) then b[i,j+k]:=b[i-1,j] + a[i,j+k];
end; s:=0;
for i:=1 to n
if s < b[n,i] then s:=b[n,i]; End;
Procedure Xuat; Begin
writeln(f2,s); writeln(f2,sao); End;
BEGIN {main}
assign(f1,fi); reset(f1); assign(f2,fo);rewrite(f2); while Not(eof(f1)) begin
Nhap;Xuli;Xuat; end;
close(f1);close(f2); END