0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-08 12:58:48 +00:00

1288. 三角形最佳路径问题

http://ybt.ssoier.cn:8088/statusx.php?runidx=15577969
This commit is contained in:
Baoshuo Ren 2022-04-03 09:11:26 +08:00
parent 1957f776aa
commit 59c3bcec25
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

34
ybt/1288/1288.cpp Normal file
View File

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