#include<iostream>
#include<iomanip>
#include<vector>
#include<algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
const int MAX_N = 50000;
typedef double royale;
vector<royale> P;
royale T[1+MAX_N], U[1+MAX_N];
royale best, q, z;
int t, n, m;
int main(void) {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> t;
P.resize(n);
REP(i, n) cin >> P[i];
sort(P.begin(), P.end());
REP(i,n) T[i] = 0.0;
T[0] = 1.0;
best = 0.0;
FOR(m, 1, n) {
q = P[n-m];
U[0] = T[0]*(1-q);
FOR(k, 1, m) {
U[k] = T[k]*(1-q) + T[k-1]*q;
}
REP(i,n) T[i] = U[i];
z = 0.0;
REP(i,n) if (i >= ((t + m + 1) / 2)) z += T[i];
if (z > best) best = z;
}
cout << fixed << setprecision(7) << 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 | #include<iostream> #include<iomanip> #include<vector> #include<algorithm> #define REP(i,n) for(int i=0;i<(n);++i) #define FOR(i,a,b) for(int i=(a);i<=(b);++i) using namespace std; const int MAX_N = 50000; typedef double royale; vector<royale> P; royale T[1+MAX_N], U[1+MAX_N]; royale best, q, z; int t, n, m; int main(void) { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> t; P.resize(n); REP(i, n) cin >> P[i]; sort(P.begin(), P.end()); REP(i,n) T[i] = 0.0; T[0] = 1.0; best = 0.0; FOR(m, 1, n) { q = P[n-m]; U[0] = T[0]*(1-q); FOR(k, 1, m) { U[k] = T[k]*(1-q) + T[k-1]*q; } REP(i,n) T[i] = U[i]; z = 0.0; REP(i,n) if (i >= ((t + m + 1) / 2)) z += T[i]; if (z > best) best = z; } cout << fixed << setprecision(7) << best << endl; return 0; } |
English