#include <cstdio> #include <cstdlib> #include <cassert> #include <array> #include <iterator> #include <algorithm> double data[50000]; double compute_prob(int i, int remaining, int n) { if (i == n) { return 1.0; } double p = data[i] * compute_prob(i + 1, remaining - 1, n); if (i + remaining + 2 <= n) { p += (1.0 - data[i]) * compute_prob(i + 1, remaining + 1, n); } return p; } int main() { int n, t; scanf("%d %d\n", &n, &t); for (int i = 0; i < n; i++) { scanf("%lf\n", &data[i]); } std::sort(std::rbegin(data), std::rend(data)); double best = 0.0; for (int i = t; i < n; i++) { best = std::max(best, compute_prob(0, t, i)); } printf("%.8lf\n", best); return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | #include <cstdio> #include <cstdlib> #include <cassert> #include <array> #include <iterator> #include <algorithm> double data[50000]; double compute_prob(int i, int remaining, int n) { if (i == n) { return 1.0; } double p = data[i] * compute_prob(i + 1, remaining - 1, n); if (i + remaining + 2 <= n) { p += (1.0 - data[i]) * compute_prob(i + 1, remaining + 1, n); } return p; } int main() { int n, t; scanf("%d %d\n", &n, &t); for (int i = 0; i < n; i++) { scanf("%lf\n", &data[i]); } std::sort(std::rbegin(data), std::rend(data)); double best = 0.0; for (int i = t; i < n; i++) { best = std::max(best, compute_prob(0, t, i)); } printf("%.8lf\n", best); return 0; } |