View Code of Problem 65

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int main() {
	int t,i,j;
	scanf("%d",&t);
	while(t--){
	
	int r;
	scanf("%d",&r);
	int a[r][r];
	for(i=0;i<r;i++){
		for(j=0;j<=i;j++){
			scanf("%d",&a[i][j]);
		}
	}
	int sum=0;
	for(i=r-1;i>=0;i--){
		for(j=0;j<=i;j++){
			if(a[i][j]+a[i-1][j]>a[i][j+1]+a[i-1][j]){
				a[i-1][j]=a[i][j]+a[i-1][j];
			}
			else{
				a[i-1][j]=a[i][j+1]+a[i-1][j];
			}
		}
	}
	printf("%d\n",a[0][0]);
	}
}

Double click to view unformatted code.


Back to problem 65