View Code of Problem 4055

#include<stdio.h>
#include<math.h>
#include<string.h>
int max(int a,int b){
	return a>b?a:b;
}
int a[1010][1010]; 
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=i;j++){
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=n-1;i>=1;i--){
		for(int j=1;j<=i;j++){
			if(a[i+1][j]>a[i+1][j+1]){
				a[i][j]+=a[i+1][j];
			}else{
				a[i][j]+=a[i+1][j+1];
			}
		}
	}
	printf("%d",a[1][1]);
}

Double click to view unformatted code.


Back to problem 4055