View Code of Problem 65

#include<stdio.h>
#include <string.h>
#include <math.h>
int main(){
	int t;
	int i,j;
	int r;
	int a[1000][100];
	scanf("%d",&t); 
	while(t--){
		scanf("%d",&r);
		for(i=1;i<=r;i++){
			for(j=1;j<=i;j++){
				scanf("%d",&a[i][j]);
			}
		}
		for(i=r-1;i>=1;i--){
			for(j=1;j<=i;j++){
				if(a[i][j]+a[i+1][j]<a[i][j]+a[i+1][j+1])
			    a[i][j]=a[i][j]+a[i+1][j+1];
			    else
			    a[i][j]=a[i][j]+a[i+1][j];
		}	
	}
	printf("%d\n",a[1][1]);
  }
  return 0;
}

Double click to view unformatted code.


Back to problem 65