제출 #647061

#제출 시각아이디문제언어결과실행 시간메모리
647061google수열 (APIO14_sequence)C++17
0 / 100
2070 ms16532 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int szn = 10001,szk=201; int dp[szn][szk],arr[szn],pre[szn],n,k; vector<int> rans; void dfs(int pl, vector<int> ans, bool p = 0){ if (!rans.empty()) return; if (p) ans.push_back(pl+1); int c = k-ans.size(); if (!c) rans = ans; for (int i = pl-1;~i;i--){ if (!rans.empty()) return; if (dp[pl][c] == dp[i][c-1]+(pre[i]*(pre[pl]-pre[i]))) dfs(i,ans,1); } } int main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> k; for (int i = 0;i<n;i++) { cin >> arr[i]; pre[i] = arr[i]; if (i) pre[i] += pre[i-1]; } memset(dp,0,sizeof(dp)); for (int c = 1;c<=k;c++){ for (int i = c;i<n;i++){ for (int j = 0;j<i;j++){ if (dp[i][c] < dp[j][c-1]+(pre[j]*(pre[i]-pre[j]))){ dp[i][c] = dp[j][c-1]+(pre[j]*(pre[i]-pre[j])); } } } } cout << dp[n-1][k] << '\n'; dfs(n-1,{}); for (auto a:rans) cout << a << ' '; 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...