0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-10 02:38:49 +00:00

P1216 [USACO1.5][IOI1994]数字三角形 Number Triangles

R40582502
This commit is contained in:
Baoshuo Ren 2020-10-26 21:39:24 +08:00 committed by Baoshuo Ren
parent 2933e72b04
commit 3b2b0091a8
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

25
problem/P1216/P1216.cpp Normal file
View File

@ -0,0 +1,25 @@
#include<bits/stdc++.h>
using namespace std;
int main() {
int n, a[1005][1005], f[1005][1005];
cin >> n;
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= i ; j++) {
cin >> a[i][j];
}
}
f[1][1] = a[1][1];
for(int i = 1 ; i <= n ; i++) {
for(int j = 1 ; j <= i+1 ; j++) {
f[i][j] = a[i][j] + max(f[i-1][j], f[i-1][j-1]);
}
}
int ans = -0x3f3f3f;
for(int i = 1 ; i <= n ; i++) {
ans = max(ans, f[n][i]);
}
cout << ans << endl;
return 0;
}