View Code of Problem 65

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

Double click to view unformatted code.


Back to problem 65