이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = (int)4000;
long long dp[MAX_N][MAX_N / 2][2];
const long long MINUS_INF = -1e15;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<long long> a(n);
for (auto& x : a) cin >> x;
for (int i = 0; i < MAX_N; ++i) {
for (int j = 0; j < MAX_N / 2; ++j) {
for (int f = 0; f <= 1; ++f) {
dp[i][j][f] = MINUS_INF;
}
}
}
dp[0][0][0] = 0;
dp[0][1][1] = a[0];
for (int i = 1; i < n; ++i) {
dp[i][0][0] = 0;
for (int j = 1; j <= (n + 1) / 2; ++j) {
dp[i][j][0] = max(dp[i - 1][j][0], dp[i - 1][j][1]);
if (dp[i - 1][j - 1][0] == MINUS_INF) {
dp[i][j][1] = MINUS_INF;
} else {
dp[i][j][1] = dp[i - 1][j - 1][0] + a[i];
}
}
}
for (int j = 1; j <= (n + 1) / 2; ++j) {
cout << max(dp[n - 1][j][0], dp[n - 1][j][1]) << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |