이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// https://oj.uz/problem/view/IZhO14_blocks
#include <bits/stdc++.h>
using namespace std;
int N, K;
int a[100005], dp[105][100005];
int main() {
cin >> N >> K;
memset(dp, 1000000, sizeof(dp));
for(int i = 1; i <= N; i ++) {
cin >> a[i];
}
// THIS VERSION IS NOT OPTIMIZED, BUT WORKS PROPERLY
for(int i = 1; i <= K; i ++) {
for(int j = i; j <= N; j ++) {
if(i == 1) {
if(j == 1) {
dp[i][j] = a[j];
}
else {
dp[i][j] = max(dp[i][j - 1], a[j]);
}
}
else if(i == j) {
dp[i][j] = dp[i - 1][j - 1] + a[j];
}
else {
int mx = a[j];
for(int k = j - 1; k >= i; k --) {
dp[i][j] = min(dp[i][j], dp[i - 1][k] + mx);
mx = max(mx, a[k]);
}
}
}
}
cout << dp[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... |