USACO 1.5.1 – Number Triangles


#include <iostream>
#include <cstdio>
using namespace std;

#define fo(ii, i0, nn, dd) for(ii=i0; ii!=nn; ii+= dd)
#define fo2(ii, i0, in, id, jj, j0, jn, jd) fo(ii, i0, in, id) fo( jj, j0, jn, jd)

int main() {
	int i, j, R, a[1001][1001];
	freopen("numtri.in", "r", stdin), freopen("numtri.out", "w", stdout);
	scanf("%d", &R);

	fo2(i, 0, R, 1, j, 0, i+1, 1)
			scanf("%d", &a[i][j]);
	fo2(i, R-1, 0, -1, j, 0, i, 1)
			a[i - 1][j] += max(a[i][j], a[i][j + 1]);

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

	return 0;
}
Advertisements

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

%d bloggers like this: