#include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, t; cin >> n >> t; vector<double> p(n); for (int i = 0; i < n; i++) { cin >> p[i]; } sort(p.begin(), p.end(), greater<double>()); vector<double> dp(2 * n + 1, 0.0); dp[n] = 1.0; double best_prob = 0.0; for (int k = 0; k < n; k++) { vector<double> new_dp(2 * n + 1, 0.0); for (int s = 0; s <= 2 * n; s++) { if (dp[s] > 0) { new_dp[s + 1] += dp[s] * p[k]; new_dp[s - 1] += dp[s] * (1 - p[k]); } } dp = new_dp; double prob = 0.0; for (int s = t + n; s <= 2 * n; s++) { prob += dp[s]; } best_prob = max(best_prob, prob); if (k == 3) break; } cout.precision(7); cout << fixed << best_prob << "\n"; 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 41 42 43 44 45 46 | #include <iostream> #include <vector> #include <algorithm> using namespace std; int main() { int n, t; cin >> n >> t; vector<double> p(n); for (int i = 0; i < n; i++) { cin >> p[i]; } sort(p.begin(), p.end(), greater<double>()); vector<double> dp(2 * n + 1, 0.0); dp[n] = 1.0; double best_prob = 0.0; for (int k = 0; k < n; k++) { vector<double> new_dp(2 * n + 1, 0.0); for (int s = 0; s <= 2 * n; s++) { if (dp[s] > 0) { new_dp[s + 1] += dp[s] * p[k]; new_dp[s - 1] += dp[s] * (1 - p[k]); } } dp = new_dp; double prob = 0.0; for (int s = t + n; s <= 2 * n; s++) { prob += dp[s]; } best_prob = max(best_prob, prob); if (k == 3) break; } cout.precision(7); cout << fixed << best_prob << "\n"; return 0; } |