이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N_MAX = 1e5;
const int K_MAX = 100;
const int INF = (1LL<<61LL)-1;
int n, k;
int dp[N_MAX+1][K_MAX+1];
int best[N_MAX+1][K_MAX+1];
int a[N_MAX];
void display(int l, int id){
for(int i = 0; i<n; i++){
if(id<=i && i<best[id][l]){
//cout<<'-';
}
else{
//cout<<' ';
}
}
//cout<<endl;
if(l>1){
display(l-1, best[id][l]);
}
}
void find(){
for(int left =0; left<=k; left++){
for(int i = n; i>=0; i--){
if(left == 0){
if( i==n){
dp[i][left] = 0;
}
else{
dp[i][left] = INF;
}
}
else if( i == n){
dp[i][left] = INF;
}
else{
dp[i][left] = INF;
int m= 0;
for(int j = i+1; j<=n; j++){
m =max(m, a[j-1]);
if(dp[i][left]> dp[j][left-1]+m){
best[i][left] = j;
}
dp[i][left] = min(dp[i][left], dp[j][left-1]+m);
}
}
}
for(int i = 0; i<=n; i++){
//cout<<dp[i][left]<<" ";
}
//cout<<endl;
}
cout<<dp[0][k]<<endl;
display(k, 0);
}
signed main(){
cin>>n>>k;
for(int i = 0; i<n; i++){
cin>>a[i];
}
find();
}
# | 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... |