AcWing 898. 数字三角形-一维
原题链接
简单
作者:
x2
,
2021-04-21 02:02:20
,
所有人可见
,
阅读 324
题目描述
样例
#include <iostream>
using namespace std;
const int N = 505;
int v[N], f[N];
int main() {
int n, ans = -0x3f3f3f3f;
cin >> n;
fill(f, f + n + 1, -0x3f3f3f3f);
fill(v, v + n + 1, -0x3f3f3f3f);
f[1] = 0;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) cin >> v[j];
for (int j = i; j >= 1; j--) f[j] = max(f[j-1], f[j]) + v[j];
}
for (int i = 1; i <= n; i++) ans = max(f[i], ans);
cout << ans << endl;
return 0;
}