Submission #47508

#TimeUsernameProblemLanguageResultExecution timeMemory
47508WaschbarSplit the sequence (APIO14_sequence)C++17
0 / 100
2 ms804 KiB
///©Waschbar #include <bits/stdc++.h> #define tmm first #define uu second.first #define vv second.second using namespace std; const int MAXN = 10; const int LOG = 20; const int INF = 1e9; const int MOD = 1e9+7; long long n, m; long long val[MAXN+1], sum[MAXN+1]; long long dp[MAXN+1][MAXN+1][201]; pair<int,int> p[MAXN+1][MAXN+1][201]; vector < short int > v; void func(int L, int R, int k) { if(k == 0) return; v.push_back(p[L][R][k].first); func(L,p[L][R][k].first,p[L][R][k].second); func(p[L][R][k].first+1,R,k-p[L][R][k].second-1); } int main() { cin >> n >> m; for(int i = 1; i <= n; i++){ cin >> val[i]; sum[i] = sum[i-1] + val[i]; } for(int i = 0; i <= n; i++) for(int j = 0; j <= n; j++) for(int k = 0; k <= m; k++){ dp[i][j][k] = -INF; dp[i][j][0] = 0; } for(int dis = 0; dis < n; dis++) for(int L = 1; L+dis <= n; L++){ int R = L+dis; for(int k = 1; k <= m; k++){ if(k > R-L) break; for(int M = L; M < R; M++) for(int P = 0; P < k; P++){ int x = dp[L][R][k]; dp[L][R][k] = max(dp[L][R][k], dp[L][M][P]+dp[M+1][R][k-P-1] +(sum[M]-sum[L-1])*(sum[R]-sum[M])); if(x != dp[L][R][k]){ p[L][R][k] = {M,P}; } } ///cout << L <<" "<<R<<" "<<k<<" "<<dp[L][R][k] << endl; } } cout << dp[1][n][m] << endl; func(1,n,m); for(int i = 0; i < v.size(); i++) cout << v[i] << " "; return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:66:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v.size(); i++)
                    ~~^~~~~~~~~~
#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...