自底向上贪心即可,其实就是dp的思想,用下面一层来更新上面一层
#include <stdio.h>
int n;
int num[100][100];
int max(int a, int b)
{
return a>b?a:b;
}
int main()
{
scanf("%d", &n);
int i, j;
for ( i = 0; i < n; i++ )
for ( j = 0; j <= i; j++ )
scanf("%d", num[i]+j);
for ( i = n-1; i > 0; i-- )
for ( j = 0 ; j < i; j++)
num[i-1][j]+=max(num[i][j], num[i][j+1]);
printf("%d\n", num[0][0]);
return 0;
}