[CODEVS1220]数字三角形

题目描述 Description
如图所示的数字三角形,从顶部出发,在每一结点可以选择向左走或得向右走,一直走到底层,要求找出一条路径,使路径上的值最大。
输入描述 Input Description
第一行是数塔层数N(1<=N<=100)。
第二行起,按数塔图形,有一个或多个的整数,表示该层节点的值,共有N行。
输出描述 Output Description
输出最大值。
样例输入 Sample Input
5
13
11 8
12 7 26
6 14 15 8
12 7 13 24 11
样例输出 Sample Output
86

var f:array[0..100,0..100] of longint;
    a:array[0..100,0..100] of longint;
    n:longint;
    i1,j1:longint;
    maxx:longint;
function max(x,y:longint):longint;
begin
  if x>y then exit(x)
  else exit(y);
end;
procedure shuzi(i,j:longint);
begin
  if i=n then f[i,j]:=a[i,j];
  if i>=n then exit;
  if f[i,j]=0 then exit;
  shuzi(i+1,j);
  shuzi(i+1,j+1);
  f[i,j]:=a[i,j]+max(f[i+1,j],f[i+1,j+1]);
end;
begin
  read(n);
  for i1:=1 to n do
   for j1:=1 to i1 do
    read(a[i1,j1]);
  fillchar(f,sizeof(f),char(-1));
  shuzi(1,1);
  writeln(f[1,1]);
end
原文地址:https://www.cnblogs.com/yangqingli/p/4709291.html