This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
mt19937 rnd(51);
#define ll long long
#define pb push_back
#define ld double
const int N = 510, INF = 1e9;
int a[N], b[N], n, k;
ld dp[N][N][N];
vector<int> ord;
ld solve(int cnt) {
dp[0][0][1] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= i; j++) {
if (i == j) {
for (int k = 1; k <= i + 1; k++) {
dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k] + (ld)b[ord[i]] / (ld)k);
dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + (ld)a[ord[i]] / (ld)cnt);
}
} else {
dp[i + 1][j][cnt] = min(dp[i + 1][j][cnt], dp[i][j][cnt]);
dp[i + 1][j + 1][cnt] = min(dp[i + 1][j + 1][cnt], dp[i][j][cnt] + (ld)a[ord[i]] / (ld)cnt);
}
}
}
return dp[n][k][cnt];
}
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
#endif // LOCAL
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
for (int k = 0; k < N; k++) {
dp[i][j][k] = INF;
}
}
}
cin >> n >> k;
ord.resize(n);
iota(ord.begin(), ord.end(), 0);
for (int i = 0; i < n; i++) {
cin >> a[i] >> b[i];
if (b[i] == -1) {
b[i] = INF;
}
}
sort(ord.begin(), ord.end(), [&](int i, int j){return b[i] < b[j] || (b[i] == b[j] && a[i] < a[j]);});
ld ans = INF;
for (int i = 1; i <= k + 1; i++) {
ans = min(ans, solve(i));
}
cout << setprecision(30) << fixed << ans << endl;
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |