You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
508 B
C++
19 lines
508 B
C++
#include <cstdio>
|
|
#include <algorithm>
|
|
using namespace std;
|
|
int a[111][111], f[111][111];
|
|
int main()
|
|
{
|
|
int n;
|
|
while (~scanf("%d", &n))
|
|
{
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= i; j++)
|
|
scanf("%d", &a[i][j]);
|
|
for (int i = 1; i <= n; i++)
|
|
for (int j = 1; j <= i; j++)
|
|
f[i][j] = max(f[i - 1][j - 1], f[i - 1][j]) + a[i][j];
|
|
printf("%d\n", *max_element(f[n], f[n] + n));
|
|
}
|
|
return 0;
|
|
} |