제출 #785705

#제출 시각아이디문제언어결과실행 시간메모리
785705acatmeowmeow수열 (APIO14_sequence)C++11
50 / 100
2086 ms131072 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int N = 1e5, MAXK = 200; int n, K, prefix[N + 5], dp[N + 5][MAXK + 5], par[N + 5][MAXK + 5]; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> K; for (int i = 1; i <= n; i++) { int x; cin >> x; prefix[i] = prefix[i - 1] + x; } for (int i = 0; i <= n; i++) { for (int j = 0; j <= K; j++) { dp[i][j] = -1e18; } } for (int i = 1; i <= n; i++) dp[i][0] = 0; for (int i = 1; i <= n; i++) { for (int j = 1; j <= min(K, i - 1); j++) { for (int k = 1; k < i; k++) { int cur = dp[k][j - 1] + (prefix[i] - prefix[k])*prefix[k]; //dp[i][j] = max(dp[i][j], dp[k][j - 1] + (prefix[i] - prefix[k - 1])*prefix[i]); if (dp[i][j] < cur) dp[i][j] = cur, par[i][j] = k; } } } cout << dp[n][K] << '\n'; int index = n, layer = K; while (true) { if (!par[index][layer]) break; else cout << par[index][layer] << " "; index = par[index][layer], layer--; } cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...