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
#include <bits/stdc++.h>
using namespace std;
const int SIZE=5e4+5;
long double tab[SIZE];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int N,T;
    cin>>N>>T;
    long double MAX=0.0,P,NM,ORG;
    char Z;

    for(int i=0;i<N;i++){cin>>tab[i];}
    sort(tab,tab+N,greater<double>());

    for(int G=T;G<=N;G+=2){
    if(tab[G-1]==0.0){break;}
    P=0;
    ORG=1.0;

    for(int i=0;i<G;i++){ORG*=tab[i];}

    int d=1<<G;

    for(int i=0;i<d;i++){
        if(__builtin_popcount(i)>(G-T)/2){continue;}
        NM=ORG;
        for(int j=0;j<G;j++){
            if(i&(1<<j)){NM=NM/tab[j]*(1.0-tab[j]);}
        }
        P+=NM;
    }
    if(MAX>P){break;}
    MAX=P;

    }
    //if(MAX<)
    cout<<fixed<<setprecision(7)<<MAX;

return 0;}