View Code of Problem 65

#include<stdio.h>

int main(){
	int T;
	scanf("%d",&T);
	while(T--){//上三角,相邻两个数,大的往上加 
		int n;
		scanf("%d",&n);
		int a[n][n];
		int i,j;
		for(i=0;i<n;i++){
			for(j=0;j<=i;j++){
				scanf("%d",&a[i][j]);
			}
		}
		for(i=n-1;i>0;i--){
			for(j=0;j<i;j++){
				if(a[i][j]>=a[i][j+1]){
					a[i-1][j]+=a[i][j];
				}
				else{
					a[i-1][j]+=a[i][j+1];
				}
			}
		}
		printf("%d\n",a[0][0]);
	}
}

Double click to view unformatted code.


Back to problem 65