-
Sample Input
3 5 7 0 2 4 3 3 2 6 1 2 3 9
Sample Output
16 12
#include <iostream> -
using namespace std;
-
int a[102][102];
-
-
int max( int x, int y)
-
{
-
if( x > y)
-
{
-
return x;
-
}
-
return y;
-
}
-
int main()
-
{
-
int i, j, x, y, n;
-
while ( cin >> n)
-
{
-
for( i = 0; i < n; i++)
-
{
-
for( j = 0; j <= i; j++)
-
{
-
cin >> a[i][j];
-
}
-
}
-
// cout << a[0][0] << endl;
-
for(i = n-2; i >= 0; i--)
-
{
-
for( j = 0; j <= i; j++)
-
{
-
x = a[i][j] + a[i+1][j];
-
y = a[i][j] + a[i+1][j+1];
-
// cout << x << " " << y << endl;
-
a[i][j] = max(x, y);
-
}
-
}
-
cout << a[0][0] << endl;
-
}
-
return 0;
-
}
joj 2511
