'commit'
This commit is contained in:
25
TangDou/AcWing/LineDP/898_ZhengXu_YiWei.cpp
Normal file
25
TangDou/AcWing/LineDP/898_ZhengXu_YiWei.cpp
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <bits/stdc++.h>
|
||||
using namespace std;
|
||||
const int N = 510;
|
||||
const int INF = 0x3f3f3f3f;
|
||||
int n;
|
||||
int f[N];
|
||||
int a[N][N];
|
||||
|
||||
int main() {
|
||||
cin >> n;
|
||||
for (int i = 1; i <= n; i++)
|
||||
for (int j = 1; j <= i; j++)
|
||||
cin >> a[i][j];
|
||||
// 预求最大,先设最小
|
||||
memset(f, -0x3f, sizeof f);
|
||||
f[1] = a[1][1]; // 递推的初始化边界
|
||||
for (int i = 2; i <= n; i++)
|
||||
for (int j = i; j >= 1; j--)
|
||||
f[j] = max(f[j - 1], f[j]) + a[i][j];
|
||||
|
||||
int res = -INF;
|
||||
for (int i = 1; i <= n; i++) res = max(res, f[i]);
|
||||
printf("%d", res);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user