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 <vector>
#include <cassert>
#include <algorithm>
using namespace std;
int N, K;
int A[509], B[509];
bool used[509];
double Answer = 1e9;
void dfs(int pos, int corp, double ti) {
if (pos == K) {
Answer = min(Answer, ti);
return;
}
for (int i = 1; i <= N; i++) {
if (used[i] == true) continue;
used[i] = true;
dfs(pos + 1, corp + 0, ti + 1.0 * A[i] / (corp + 1));
if (B[i] != -1) {
dfs(pos + 1, corp + 1, ti + 1.0 * B[i] / (corp + 1));
}
used[i] = false;
}
}
int main() {
// Step #1. Input
cin >> N >> K;
for (int i = 1; i <= N; i++) cin >> A[i] >> B[i];
assert(N <= 7);
// Step #2. Brute Force
dfs(0, 0, 0.0);
// Step #3. Output
printf("%.12lf\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... |