BZOJ传送门
洛谷传送门
题解:
首先这种跟二进制位有关的期望题很显然就是考虑Min-Max容斥。
这道题的集合显然就是所有二进制位。
于是 E ( max ( S ) ) = ∑ T ⊆ S ( − 1 ) ∣ T ∣ + 1 E ( min ( T ) ) E(\max(S))=\sum_{T\subseteq S}(-1)^{|T|+1}E(\min(T)) E(max(S))=T⊆S∑(−1)∣T∣+1E(min(T))
显然 T T T集合中的元素期望最早时间出现就是 1 ∑ U ∩ T ! = ∅ P U \dfrac{1}{\sum\limits_{U\cap T !=\empty}P_U} U∩T!=∅∑PU1
我们需要求所有和一个集合交不为空的集合的 P P P之和。
转化为求所有和一个集合交为空的集合的 P P P之和,发现就是该集合补集的所有子集,直接用快速莫比乌斯变换就行了。
代码:
#include<bits/stdc++.h>
#define ll long long
#define re register
#define gc get_char
#define cs const
namespace IO{
inline char get_char(){
static cs int Rlen=1<<22|1;
static char buf[Rlen],*p1,*p2;
return (p1==p2)&&(p2=(p1=buf)+fread(buf,1,Rlen,stdin),p1==p2)?EOF:*p1++;
}
inline double getdb(){
char c;
while(!isdigit(c=gc()));double x=c^48;
while(isdigit(c=gc()))x=(x*10)+(c^48);
if(c!='.')return x;double y=1;
while(isdigit(c=gc()))x+=(y/=10)*(c^48);
return x;
}
}
using namespace IO;
using std::cerr;
using std::cout;
cs int N=1<<20|1;
double a[N];
int popcount[N];
signed main(){
#ifdef zxyoi
freopen("or.in","r",stdin);
#endif
int len;scanf("%d",&len);len=1<<len;int ok=0;
for(int re i=0;i<len;++i)a[i]=getdb(),popcount[i]=popcount[i>>1]^(i&1);
for(int re i=0;i<len;++i)if(a[i]>1e-6)ok|=i;
if(ok!=len-1)puts("INF"),exit(0);
for(int re i=1;i<len;i<<=1)
for(int re j=0;j<len;j+=i<<1)
for(int re k=0;k<i;++k)a[i|k|j]+=a[k|j];
double ans=0;
for(int re i=1;i<len;++i){
double val=1/(1-a[(len-1)^i]);
popcount[i]?ans+=val:ans-=val;
}
printf("%.12f",ans);
return 0;
}