//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define int long long
#define ld long double
using namespace std;
const int INF = 1e18;
const int mod = 1e9+7;
const int N = 101;
pair<ld,int> dp[N][N][N];
signed main() {
int n,k;
cin >> n >> k;
vector <pair<int,int>> vec(n);
for (int i = 0;i < n;i++) {
cin >> vec[i].first >> vec[i].second;
}
for (int i = 0;i < N;i++) {
for (int j = 0;j < N;j++) {
for (int z = 0;z < N;z++) {
dp[i][j][z] = {INF,INF};
}
}
}
for (int i = 0;i < n;i++) {
dp[i][0][0] = {0,0};
dp[i][1][0] = {vec[i].first,vec[i].first};
if (vec[i].second != -1)dp[i][0][1] = {vec[i].second,0};
}
for (int i = 0;i < n - 1;i++) {
for (int j = 0;j <= n;j++) {
for (int z = 0;z <= n;z++) {
//dp[i][j][z]
if (j != n - 1) {
pair<ld,int> res = dp[i][j][z];
res.first -= (res.second / (1.0l * (z + 1)));
res.second += vec[i+1].first;
res.first += (res.second / (1.0l * (z + 1)));
if (dp[i+1][j+1][z].first > res.first) {
dp[i+1][j+1][z] = res;
}else if (dp[i+1][j+1][z].first == res.first) {
dp[i+1][j+1][z].second = max(dp[i+1][j+1][z].second,res.second);
}
}
if (dp[i+1][j][z].first > dp[i][j][z].first) {
dp[i+1][j][z] = dp[i][j][z];
}else if (dp[i+1][j][z].first == dp[i][j][z].first) {
dp[i+1][j][z].second = max(dp[i+1][j][z].second,dp[i][j][z].second);
}
if (z != n - 1 && vec[i+1].second != -1) {
pair<ld,int> res = dp[i][j][z];
res.first -= (res.second / (1.0l * (z + 1)));
res.first += (vec[i+1].second / (1.0l * (z + 1)));
res.first += (res.second / (1.0l * (z + 2)));
if (dp[i+1][j][z+1].first > res.first) {
dp[i+1][j][z+1] = res;
}else if (dp[i+1][j][z+1].first == res.first) {
dp[i+1][j][z+1].second = max(dp[i+1][j][z+1].second,res.second);
}
}
}
}
}
ld best = INF;
for (int i = 0;i <= k;i++) {
best = min(best,dp[n-1][i][k-i].first);
}
cout << best << "\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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |