USACO : Number Triangles


/*
ID: tausiq11
PROG: numtri
LANG: C++
*/

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#include <numeric>
#define INT_MAX 2147483647
#define INT_MIN -2147483647
#define pi acos(-1.0)
#define N 1000000
#define LL unsigned long long
using namespace std;

int input [1000 + 3] [1000 + 3];

int main ()
{
    freopen ("numtri.in", "r", stdin);
    freopen ("numtri.out", "w", stdout);

    int r;
    scanf ("%d", &r);

    for ( int i = 0; i < r; i++ )
        for ( int j = 0; j <= i; j++ ) scanf ("%d", &input [i] [j]);

    for ( int i = r - 1; i >= 1; i-- )
        for ( int j = 0; j < i; j++ )
            input [i - 1] [j] += max (input [i] [j], input [i] [j + 1]);

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

	return 0;
}

// @END_OF_SOURCE_CODE
Advertisements

One thought on “USACO : Number Triangles

  1. USER: [tausiq11]
    TASK: numtri
    LANG: C++
    
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.011 secs, 6812 KB]
       Test 2: TEST OK [0.000 secs, 6812 KB]
       Test 3: TEST OK [0.000 secs, 6812 KB]
       Test 4: TEST OK [0.000 secs, 6812 KB]
       Test 5: TEST OK [0.000 secs, 6812 KB]
       Test 6: TEST OK [0.011 secs, 6812 KB]
       Test 7: TEST OK [0.054 secs, 6812 KB]
       Test 8: TEST OK [0.022 secs, 6812 KB]
       Test 9: TEST OK [0.248 secs, 6812 KB]
    
    All tests OK.
    Your program ('numtri') produced all correct answers!  This is your
    submission #2 for this problem.  Congratulations!
    

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