You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
622 B

#include <bits/stdc++.h>
using namespace std;
const int N = 510;
const int INF = 0x3f3f3f3f;
int n;
int f[N];
int a[N][N];
int main() {
cin >> n;
for (int i = 1; i <= n; i++)
for (int j = 1; j <= i; j++)
cin >> a[i][j];
// 预求最大,先设最小
memset(f, -0x3f, sizeof f);
f[1] = a[1][1]; // 递推的初始化边界
for (int i = 2; i <= n; i++)
for (int j = i; j >= 1; j--)
f[j] = max(f[j - 1], f[j]) + a[i][j];
int res = -INF;
for (int i = 1; i <= n; i++) res = max(res, f[i]);
printf("%d", res);
return 0;
}