0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 19:08:47 +00:00

P2964 [USACO09NOV]A Coin Game S

https://www.luogu.com.cn/record/77095873
This commit is contained in:
Baoshuo Ren 2022-06-08 14:34:19 +08:00
parent 6cab6f75a8
commit 7166536294
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

43
Luogu/P2964/P2964.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 2005;
// f[当前位置][上一组长度]
int n, a[N], s[N], f[N][N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = n; i; i--) {
s[i] = s[i + 1] + a[i];
}
for (int i = n; i; i--) {
for (int j = 1, k = 1; j <= n; j++, k += 2) {
f[i][j] = f[i][j - 1];
if (k <= n - i + 1) {
f[i][j] = std::max(f[i][j], s[i] - f[i + k][k]);
}
if (k + 1 <= n - i + 1) {
f[i][j] = std::max(f[i][j], s[i] - f[i + k + 1][k + 1]);
}
}
}
cout << f[1][1] << endl;
return 0;
}