0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-24 03:31:59 +00:00

1258. 数字金字塔

http://ybt.ssoier.cn:8088/statusx.php?runidx=15554681
This commit is contained in:
Baoshuo Ren 2022-04-01 14:43:04 +08:00
parent d474714691
commit 733514751c
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

33
ybt/1258/1258.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1005;
int r, g[N][N], f[N][N], ans;
int main() {
std::ios::sync_with_stdio(false);
cin >> r;
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= i; j++) {
cin >> g[i][j];
}
}
for (int i = 1; i <= r; i++) {
for (int j = 1; j <= i; j++) {
f[i][j] = std::max(f[i - 1][j - 1], f[i - 1][j]) + g[i][j];
}
}
for (int i = 1; i <= r; i++) {
ans = std::max(ans, f[r][i]);
}
cout << ans << endl;
return 0;
}