#include <bits/stdc++.h> using namespace std; double dp[50123]; int main() { int n, t; scanf("%d%d", &n, &t); vector<double> ps(n); for (double& x : ps) { scanf("%lf", &x); } double answer = 0; sort(ps.rbegin(), ps.rend()); dp[1] = 1; int low = 1, high = 1; for (int cnt = 1; cnt <= n; cnt++) { double p = ps[cnt-1]; for (int i = high + 1; i >= low; i--) { dp[i] = dp[i] * (1 - p) + dp[i-1] * p; } high++; double maybe = 0; for (int i = low - 1; i <= high - 1; i++) { if (i - (cnt - i) >= t) { maybe += dp[i+1]; } } answer = max(answer, maybe); if (high - low == 4000) { if (dp[low] < dp[high]) { low++; } else { high--; } } } printf("%.10lf\n", answer); }
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 | #include <bits/stdc++.h> using namespace std; double dp[50123]; int main() { int n, t; scanf("%d%d", &n, &t); vector<double> ps(n); for (double& x : ps) { scanf("%lf", &x); } double answer = 0; sort(ps.rbegin(), ps.rend()); dp[1] = 1; int low = 1, high = 1; for (int cnt = 1; cnt <= n; cnt++) { double p = ps[cnt-1]; for (int i = high + 1; i >= low; i--) { dp[i] = dp[i] * (1 - p) + dp[i-1] * p; } high++; double maybe = 0; for (int i = low - 1; i <= high - 1; i++) { if (i - (cnt - i) >= t) { maybe += dp[i+1]; } } answer = max(answer, maybe); if (high - low == 4000) { if (dp[low] < dp[high]) { low++; } else { high--; } } } printf("%.10lf\n", answer); } |