이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for(ll i=ll(a); i<ll(b); i++)
#define repn(i, a, b) for(ll i=ll(b)-1; i>=ll(a); i--)
#define ff first
#define ss second
#define si size()
#define pb push_back
#define be begin()
#define en end()
const ll N=110;
const ll K=6;
const ll inf=(1e9);
vector<vector<ll>> dp(N, vector<ll> (K, inf));
vector<vector<ll>> mx(N, vector<ll> (N));
vector<ll> a(N);
ll sol(ll n, ll k){
if(n<k) return inf;
if(n==0 && k==0) return 0;
if(n==1 && k==1) return a[1];
if(n==2 && k==1) return max(a[1], a[2]);
if(n==2 && k==2) return a[1]+a[2];
if(dp[n][k]!=inf) return dp[n][k];
rep(i, 0, n){
dp[n][k]=min(dp[n][k], sol(i, k-1)+mx[i+1][n]);
}
return dp[n][k];
}
void solve(){
ll n, k;
cin>>n>>k;
rep(i, 1, n+1){
cin>>a[i];
}
rep(i, 1, n+1){
mx[i][i]=a[i];
rep(j, i+1, n+1){
mx[i][j]=max(a[j], mx[i][j-1]);
}
}
cout<<sol(n, k);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll t=1;
//~ cin>>t;
while(t--){
solve();
}
return 0;
}
# | 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... |