이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 110;
int n, k;
int dp[maxn][maxn];
int a[maxn];
int main() {
cin>>n>>k;
int prefmax = 0;
for(int i=1;i<=n;i++) {
cin>>a[i];
prefmax = max(prefmax, a[i]);
dp[i][1] = prefmax;
}
for(int d=2;d<=k;d++) {
for(int i=d;i<=n;i++) {
dp[i][d] = INT_MAX;
int prefmax = 0;
for(int p=i;p>=d;p--) {
prefmax = max(prefmax, a[p]);
dp[i][d] = min(dp[i][d], dp[p-1][d-1] + prefmax);
}
}
}
cout<<dp[n][k]<<"\n";
}
# | 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... |