题意:给定n件物品,每件物品让周驿东开心的概率为a[i]

要求从中选一些,使得周驿东恰好开心一次的概率最大

n<=1e4,0<=a[i]<=1

思路:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 typedef unsigned int uint;
 5 typedef unsigned long long ull;
 6 typedef pair<int,int> PII;
 7 typedef pair<ll,ll> Pll;
 8 typedef vector<int> VI;
 9 typedef vector<PII> VII;
10 #define N  21000
11 #define M  4100000
12 #define fi first
13 #define se second
14 #define MP make_pair
15 #define pi acos(-1)
16 #define mem(a,b) memset(a,b,sizeof(a))
17 #define rep(i,a,b) for(int i=(int)a;i<=(int)b;i++)
18 #define per(i,a,b) for(int i=(int)a;i>=(int)b;i--)
19 #define lowbit(x) x&(-x)
20 #define Rand (rand()*(1<<16)+rand())
21 #define id(x) ((x)<=B?(x):m-n/(x)+1)
22 #define ls p<<1
23 #define rs p<<1|1
24
25 const ll MOD=1e9+7,inv2=(MOD+1)/2;
26       double eps=1e-6;
27       int INF=1e9;
28       int dx[4]={-1,1,0,0};
29       int dy[4]={0,0,-1,1};
30
31       double a[N],b[N],c[N],t1[N],t2[N];
32
33 int read()
34 {
35    int v=0,f=1;
36    char c=getchar();
37    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
38    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
39    return v*f;
40 }
41
42 int main()
43 {
44     //freopen("1.in","r",stdin);
45     //freopen("1.out","w",stdout);
46
47     int cas;
48     scanf("%d",&cas);
49
50     while(cas--)
51     {
52         int n=read();
53         double ans=0;
54         int m=0;
55         rep(i,1,n)
56         {
57             scanf("%lf",&a[i]);
58             if(a[i]<=0.5) b[++m]=a[i];
59             ans=max(ans,a[i]);
60         }
61         sort(b+1,b+1+m);
62         double p=0,w=1.0;
63         per(i,m,1)
64         {
65             double np=p*(1.0-b[i])+w*b[i];
66             double nw=w*(1.0-b[i]);
67             if(np<=p) break;
68             p=np;
69             w=nw;
70         }
71         ans=max(ans,p);
72         printf("%.10f\n",ans);
73
74     }
75
76
77     return 0;
78 }
02-13 03:45