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 <iostream>
#include <algorithm>
using namespace std;
struct Election {
int a, b;
};
bool operator<(const Election &a1, const Election &a2) {
if (a1.b < a2.b) return true;
if (a1.b > a2.b) return false;
if (a1.a < a2.a) return true;
return false;
}
int N, K;
Election X[509];
double dp[509][509][509]; // (pos, total votes, cooperator)
double solve(int Goal) {
// Initialize [1]
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] = 1e9;
}
}
// Dynamic Programming
dp[0][0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = 0; j <= K; j++) {
for (int k = 0; k <= Goal; k++) {
dp[i + 1][j + 0][k + 0] = min(dp[i + 1][j + 0][k + 0], dp[i][j][k]);
dp[i + 1][j + 1][k + 0] = min(dp[i + 1][j + 1][k + 0], dp[i][j][k] + 1.0 * X[i + 1].a / (Goal + 1));
dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k] + 1.0 * X[i + 1].b / (k + 1));
}
}
}
// Return Value
return dp[N][K][Goal];
}
int main() {
// Step #1. Input
cin >> N;
cin >> K;
for (int i = 1; i <= N; i++) {
cin >> X[i].a >> X[i].b;
if (X[i].b == -1) X[i].b = 1000000;
}
// Step #2. Sorting
sort(X + 1, X + N + 1);
// Step #3. Brute Force
double Answer = 1e9;
for (int i = 0; i <= K; i++) {
double ret = solve(i);
Answer = min(Answer, ret);
}
// Step #4. Output
printf("%.15lf\n", Answer);
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... |