Description 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure 1 shows a number triangle. Write a program that calculates the highes
#include<stdio.h>
#include<string.h>
#define max(a,b)((a)>(b))?(a):(b)
int a[101][101],d[101][101];
int n;
int dp(int i,int j)
{
if(d[i][j]>=0)return d[i][j];
return d[i][j]=a[i][j]+(i==n-1?0:max(dp(i+1,j),dp(i+1,j+1)));
}
int main()
{
int i,j;
while(scanf("%d",&n)!=EOF)
{
for(i=0;i<n;i++)
for(j=0;j<i+1;j++)
scanf("%d",&a[i][j]);
memset(d,-1,sizeof(d));
printf("%d\n",dp(0,0));
}
return 0;
}