View Code of Problem 65

#include<iostream>
#include<math.h>
#include<cstring>
using namespace std;
typedef struct student{
	char name[100];
	int heigh;
	int money;
}s;
int main()
{
	int t;
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		int a[n][n];
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<=i;j++){
			cin>>a[i][j];	
			}
		}
		for(int i=n-2;i>=0;i--){
			for(int j=0;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];
				}
		}
		}
		cout<<a[0][0]<<endl;
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 65