이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
///©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;
}
컴파일 시 표준 에러 (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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |