제출 #905264

#제출 시각아이디문제언어결과실행 시간메모리
905264andro수열 (APIO14_sequence)C++14
0 / 100
2040 ms12376 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n, m; cin >> n >> m; vector<int> a(n + 1); for(int i = 1; i <= n; i++) { cin >> a[i]; } vector<int> pref(n + 1); vector<int> suf(n + 2); for(int i = 1; i <= n; i++) { pref[i] = pref[i - 1] + a[i]; } for(int i = n; i > 0; i--) { suf[i] = suf[i + 1] + a[i]; } vector<vector<int>> dp(n + 1, vector<int>(m + 1)); for(int i = 0; i <= n; i++) { for(int j = 0; j <= m; j++) { dp[i][j] = 0; } } vector<vector<int>> P(n + 1, vector<int>(m + 1)); for(int i = 1; i <= n; i++) { dp[i][1] = (pref[i]) * (suf[i + 1]); P[i][1] = i; } for(int i = 1; i <= n; i++) { for(int j = 2; j < i; j++) { for(int k = 1; k < i; k++) { //dp[i][j] = max(dp[i][j], dp[k][j - 1] + (pref[i] - pref[k]) * suf[i + 1]); int s = dp[k][j - 1] + (pref[i] - pref[k]) * suf[i + 1]; if(s > dp[i][j]) { P[i][j] = k; dp[i][j] = s; } } } } int ans = 0; for(int i = m + 1; i <= n; i++) { ans = max(ans, dp[i][m]); } cout << ans << "\n"; }
#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...