View Code of Problem 65

#include<iostream>
using namespace std;
int main(){
	int t;
	cin>>t;
	while(t--){
		int r,a[999][999];
		cin>>r;
		for(int i=0;i<r;i++)
	   	for(int j=i;j>=0;j--){
		cin>>a[i][j];
		}
		for(int i=r-1;i>=0;i--)
		for(int j=0;j<r;j++ ){
			if(a[i][j]<a[i][j+1])
			{
				a[i-1][j]+=a[i][j+1];
			}else{
				a[i-1][j]+=a[i][j];
			}
		}
		cout<<a[0][0]<<endl;
	} 
	return 0;
}

Double click to view unformatted code.


Back to problem 65