fork download
  1. program discesa;
  2. Uses Math;
  3. var A,i,j, ans:integer;
  4. tab, DP :array[1..10,1..10] of integer;
  5. begin
  6. (*assign(input, 'input.txt'); reset(input);
  7.   assign(output, 'output.txt'); rewrite(output);*)
  8. readln(A);
  9. for i:=1 to A do
  10. begin
  11. for j:=1 to i do read(tab[i,j]);
  12. readln;
  13. end;
  14. for i:=1 to A do
  15. for j:=1 to A do DP[i,j]:=0;
  16. DP[1,1]:=tab[1,1]; DP[2,1]:=DP[1,1]+tab[2,1]; DP[2,2]:=DP[1,1]+tab[2,2];
  17. for i:=2 to A do DP[i,1]:=DP[i-1,1]+ tab[i,1];
  18. for i:=3 to A do
  19. for j:=2 to i do
  20. DP[i,j]:=max(DP[i-1,j-1]+tab[i,j],DP[i-1,j]+tab[i,j]);
  21. ans:=0;
  22. for i:=1 to A do if DP[A,i]>ans then ans:=DP[A,i] ;
  23. writeln(ans);
  24. end.
  25.  
Success #stdin #stdout 0s 5320KB
stdin
6
42
11 13
41 37 38
5 8 11 9
22 27 31 18 32
12 8 9 8 10 11
stdout
145