이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
int N, K;
vector <int> t;
const int maxn = 5000 + 1;
ll dp[maxn][maxn];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> N >> K;
t.resize(N+1);
for (int i = 1; i <= N; i++)
cin >> t[i];
ll ans = 1e18;
for (int i = 0; i <= N; i++) {
fill(dp[i], dp[i] + maxn, 1e18);
}
dp[0][0] = 0;
for (int j = 1; j <= N; j++) {
for (int k = 1; k <= K; k++) {
for (int i = j; i <= N; i++) {
dp[i][k] = min(dp[i][k], dp[j-1][k-1] + t[i] - t[j] + 1);
if (i == N)
ans = min(ans, dp[i][k]);
}
}
}
cout << ans << '\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... |