#include <bits/stdc++.h> #define ll long long #define db double #define fors(u, n, s) for(ll u = (s); u < (n); u++) #define foru(u, n) fors(u, n, 0) #define f first #define s second #define vec vector #define pb push_back #define ir(a, b, x) (((a) <= (x)) && ((x) <= (b))) using namespace std; const int N = 5e4 + 100; int n, t; const db eps = 1e-30; db _dp[2*N]; db _dp_[2*N]; db* dp = _dp; db* dp_ = _dp_; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n >> t; vec<db> ps; ps.resize(n); foru(i, n) { db x; cin >> x; ps[i]=x; } foru(i, n) ps[i] *= -1; sort(ps.begin(), ps.end()); foru(i, n) ps[i] *= -1; int l = N; int r = N; dp[N] = 1; db ans = 0; if(t==0) ans = 1; for(auto p : ps){ l --; r ++; fors(i, r+1, l) {dp_[i] = 0;} for(int i = l+1; i < r; i += 2) { dp_[i+1] += dp[i]*p; dp_[i-1] += dp[i]*(1-p); } swap(dp, dp_); db subans = 0; fors(i, r+1, max(N+t, l)) { subans += dp[i]; } ans = max(ans, subans); while(dp[l] <= eps) l++; while(dp[r] <= eps) r--; } cout << fixed << setprecision(7); cout << ans; 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 67 68 69 70 71 72 73 74 75 76 77 | #include <bits/stdc++.h> #define ll long long #define db double #define fors(u, n, s) for(ll u = (s); u < (n); u++) #define foru(u, n) fors(u, n, 0) #define f first #define s second #define vec vector #define pb push_back #define ir(a, b, x) (((a) <= (x)) && ((x) <= (b))) using namespace std; const int N = 5e4 + 100; int n, t; const db eps = 1e-30; db _dp[2*N]; db _dp_[2*N]; db* dp = _dp; db* dp_ = _dp_; int main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); cin >> n >> t; vec<db> ps; ps.resize(n); foru(i, n) { db x; cin >> x; ps[i]=x; } foru(i, n) ps[i] *= -1; sort(ps.begin(), ps.end()); foru(i, n) ps[i] *= -1; int l = N; int r = N; dp[N] = 1; db ans = 0; if(t==0) ans = 1; for(auto p : ps){ l --; r ++; fors(i, r+1, l) {dp_[i] = 0;} for(int i = l+1; i < r; i += 2) { dp_[i+1] += dp[i]*p; dp_[i-1] += dp[i]*(1-p); } swap(dp, dp_); db subans = 0; fors(i, r+1, max(N+t, l)) { subans += dp[i]; } ans = max(ans, subans); while(dp[l] <= eps) l++; while(dp[r] <= eps) r--; } cout << fixed << setprecision(7); cout << ans; return 0; } |