mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-24 01:08:47 +00:00
898. 数字三角形
https://www.acwing.com/problem/content/submission/code_detail/8843866/
This commit is contained in:
parent
aac871e5ec
commit
a9de927b3a
27
AcWing/898/898.cpp
Normal file
27
AcWing/898/898.cpp
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user