CodeChef (SUMTRIAN)


Question:
http://www.codechef.com/problems/SUMTRIAN/

Solutions:


#include <iostream>
using namespace std;

int main ()
{
    int n;
    cin >> n;

    int row;
    int array [102] [102];

    while ( n-- ) {

        cin >> row;

        for ( int i = 0; i < row; i++ ) {
            for ( int j = 0; j <= i; j++ )
                cin >> array [i] [j];
        }

        for ( int i = row - 2; i >= 0; i-- ) {
            for ( int j = 0; j <= i; j++ ) {
                if ( array &#91;i + 1&#93; &#91;j&#93; > array [i + 1] [j + 1] )
                    array [i] [j] += array [i + 1] [j];

                else
                    array [i] [j] += array [i + 1] [j + 1];
            }
        }

        printf ("%d\n", array [0] [0]);

    }

    return 0;
}


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s