View Code of Problem 65

#include <stdio.h>
#include <string.h>
int max(int a,int b){
	if(a>b)  return a;
	else  return b;
}
int main(){
	int n;
	int h;
	int k;
	int i,j;
	int tri[200][200]={0};
	scanf("%d",&n);
	for(i=01;i<=n;i++){
		scanf("%d",&h);
		for(k=1;k<=h;k++)
			for(j=1;j<=k;j++)
				scanf("%d",&tri[k][j]);
		for(k=h;k>=1;k--){
			for(j=1;j<=k;j++){
				tri[k][j]+=max(tri[k+1][j],tri[k+1][j+1]);
			}
		}
		printf("%d\n",tri[1][1]);
		memset(tri,0,sizeof(tri));
	}
}

Double click to view unformatted code.


Back to problem 65