# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
465280 | 2021-08-15T13:30:22 Z | dattranxxx | Stove (JOI18_stove) | C++11 | 0 ms | 0 KB |
/* * Author : shora */ #include <bits/stdc++.h> #define print(_v) for (auto &_ : _v) {cerr << _ << ' ';} cerr << endl; using namespace std; using ll = long long; const int oo = 1e9; const int N = 5000; int a[N+1]; int n, k; int dp[N+1][N+1]; int main() { cin.tie(0)->sync_with_stdio(0); cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> a[i]; // dp[j][i] = a[i] + min(dp[j-1][u-1] - a[u]) + 1 : u <= i // dp[j][i] = a[i] + g[j-1] + 1 voi g[i] = min(dp[i][p-1] + a[p]) // dp[i] la mot day tang // a[i] la mot day tang memset(dp, 0x3f, sizeof(dp)); for (int i = 0; i <= k; ++i) dp[i][0] = 0; for (int i = 1; i <= k; ++i) { int mn = oo; for (int j = 1; j <= n; ++j) { mn = min(mn, dp[i-1][j-1] - a[j]); dp[i][j] = a[j] + mn + 1; res = min(res, dp[i][j]); } } cout << dp[k][n]; return 0; }