今天郁闷了,贴个小代码
#include <stdio.h>
#include <string.h>
int max,n,i,j,a[110][110],f[110][110];

int main()
{
memset(f,0,sizeof(f));
scanf("%d",&n);
for (i=1;i<=n;i++) for (j=1;j<=i;j++) scanf("%d",&a[i][j]);
f[1][1]=a[1][1];

for (i=1;i<n;i++) for (j=1;j<=i;j++)
{
f[i+1][j]>?=f[i][j]+a[i+1][j];
f[i+1][j+1]>?=f[i][j]+a[i+1][j+1];
}
for (max=0,i=1;i<=n;i++) max>?=f[n][i];
printf("%d\n",max);
return 0;
}