Page 85 - C:\Users\Admin\Desktop\Sach mem upweb\
P. 85

100 Problems & Solutions                                                Trang 85


                         a,b:mang;
                      Procedure Input;
                      Begin
                      clrscr;
                      Assign(f,'input.txt');
                      reset(f);
                      readln(f,n);
                      for j:=1 to n do
                        begin
                           for i:=2 to j+1 do
                           read(f,a[j,i]);
                        end;
                      close(f);
                      end;
                      {----------------------------------}
                      Function Max(m,n:integer):integer;
                      Begin
                           if n>m then Max:=n
                           else Max:=m;
                      end;
                      {----------------------------------}
                      Procedure MakeArrayOfQHD;
                      Begin
                           b[1,2]:=a[1,2];
                           for j:=1 to n do b[j,1]:=-maxint;
                           for i:=3 to n do b[1,i]:=-maxint;
                           for j:=2 to n do
                               begin
                                    for i:=2 to j+1 do
                                      b[j,i]:=a[j,i]+max(b[j-1,i],b[j-1,i-1]);
                               end;
                      end;
                      {-----------------------------------}
                      Procedure FindMax;
                      var max:integer;
                      Begin
                           max:=b[n,1];
                           for i:=2 to n do
                           if b[n,i]>max then max:=b[n,i];
                           writeln('Smax:=',max);
                           readln;
                      end;
                      {------------------------------------}
                      BEGIN
                           Input;
                           makearrayofQHD;
                           FindMax;
                      END.






                      Tin học & Nhà trường                                       100 Đề Toán - Tin học
   80   81   82   83   84   85   86   87   88   89   90