#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pll pair<ll,ll>
#define pii pair<int,int>
#define pb push_back
#define epb emplace_back
#define f first
#define s second
#define inf 1e9+1;
using namespace std;
ll dp[100001][101];
void solve(){
int n,k;cin>>n>>k;
vector<ll>a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i];
}
ll mx[n+1][n+1];
for(int i=1;i<=n;i++){
for(int j=1;j<=k;j++)dp[i][j]=1e12;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
ll mx1=0;
for(int l=j;l<=i;l++)mx1=max(mx1,a[l]);
mx[j][i]=mx1;
}
}
for(int i=1;i<=n;i++)mx[0][i]=mx[1][i];
dp[1][1]=a[1];
for(int i=2;i<=n;i++){
for(int j=1;j<=i;j++){
if(j==1){dp[i][j]=mx[1][i];continue;}
for(int l=j-1;l<i;l++){
dp[i][j]=min(dp[l][j-1]+mx[l][i],dp[i][j]);
}
}
}
cout<<dp[n][k];
}
int main(){
int t;t=1;
while(t--){
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |