0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:25:24 +00:00
Baoshuo Ren 2021-11-15 15:40:15 +08:00 committed by Baoshuo Ren
parent aac871e5ec
commit a9de927b3a
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

27
AcWing/898/898.cpp Normal file
View File

@ -0,0 +1,27 @@
#include <bits/stdc++.h>
using namespace std;
int n, g[505][505], f[505][505], ans;
int main() {
cin >> n;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= i; j++) {
cin >> g[i][j];
}
}
memset(f, 0xc0, sizeof(f));
f[1][1] = g[1][1];
for (int i = 2; i <= n; i++) {
for (int j = 1; j <= i; j++) {
f[i][j] = max(f[i - 1][j], f[i - 1][j - 1]) + g[i][j];
}
}
ans = 0xc0c0c0c0;
for (int i = 1; i <= n; i++) {
ans = max(ans, f[n][i]);
}
cout << ans << endl;
return 0;
}