#include <bits/stdc++.h> using namespace std; typedef int64_t ll; typedef uint64_t ull; typedef unsigned int ui; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<long long> vll; constexpr ll LINF = 1e18; constexpr int INF = 1e9; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(18); 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>()); double dp[n + 1][n + 1]; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { dp[i][j] = 0.0; } } dp[0][0] = 1.0; for (int i = 1; i <= n; ++i) { dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]); for (int j = 1; j <= i; ++j) { dp[i][j] = dp[i - 1][j - 1] * p[i - 1] + dp[i - 1][j] * (1 - p[i - 1]); } } // for (int i = 0; i <= n; ++i) { // for (int j = 0; j <= n; ++j) { // cout << dp[i][j] << ' '; // } // cout << '\n'; // } double best = 0; for (int i = t; i <= n; ++i) { int correct_to_pass = i - (i - t) / 2; double sum = 0; for (int j = correct_to_pass; j <= i; ++j) { sum += dp[i][j]; } if (sum > best) { best = sum; } } cout << setprecision(18) << best << endl; 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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | #include <bits/stdc++.h> using namespace std; typedef int64_t ll; typedef uint64_t ull; typedef unsigned int ui; typedef pair<int, int> pii; typedef vector<int> vi; typedef vector<long long> vll; constexpr ll LINF = 1e18; constexpr int INF = 1e9; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(18); 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>()); double dp[n + 1][n + 1]; for (int i = 0; i <= n; ++i) { for (int j = 0; j <= n; ++j) { dp[i][j] = 0.0; } } dp[0][0] = 1.0; for (int i = 1; i <= n; ++i) { dp[i][0] = dp[i - 1][0] * (1 - p[i - 1]); for (int j = 1; j <= i; ++j) { dp[i][j] = dp[i - 1][j - 1] * p[i - 1] + dp[i - 1][j] * (1 - p[i - 1]); } } // for (int i = 0; i <= n; ++i) { // for (int j = 0; j <= n; ++j) { // cout << dp[i][j] << ' '; // } // cout << '\n'; // } double best = 0; for (int i = t; i <= n; ++i) { int correct_to_pass = i - (i - t) / 2; double sum = 0; for (int j = correct_to_pass; j <= i; ++j) { sum += dp[i][j]; } if (sum > best) { best = sum; } } cout << setprecision(18) << best << endl; return 0; } |