好像还可以 M i n − M a x Min-Max Min−Max容斥
f
[
i
]
[
j
]
f[i][j]
f[i][j]表示前
i
i
i次,状态为
j
j
j的概率
令
m
=
2
n
m=2^n
m=2n
则要求的答案为
∑
k
=
1
∞
k
∗
(
f
[
k
]
[
m
−
1
]
−
f
[
k
−
1
]
[
m
−
1
]
)
\sum_{k=1}^{\infty}k*(f[k][m-1]-f[k-1][m-1])
∑k=1∞k∗(f[k][m−1]−f[k−1][m−1])
=
(
lim
k
→
∞
k
f
[
k
]
[
m
−
1
]
)
−
∑
k
=
0
∞
f
[
k
]
[
m
−
1
]
=(\lim_{k\rightarrow \infty}kf[k][m-1])-\sum_{k=0}^{\infty}f[k][m-1]
=(limk→∞kf[k][m−1])−∑k=0∞f[k][m−1]
且
f
[
k
]
[
x
]
f[k][x]
f[k][x]就相当于把
p
p
p做
k
k
k次集合
a
n
d
and
and卷积第
x
x
x项系数
则
F
M
T
FMT
FMT之后得到
g
[
x
]
=
−
∑
k
=
0
∞
p
[
x
]
k
g[x]=-\sum_{k=0}^{\infty}p[x]^k
g[x]=−∑k=0∞p[x]k
而这是一个等比数列,在趋近无穷时得到
g
[
x
]
=
−
1
1
−
p
[
x
]
g[x]=\frac{-1}{1-p[x]}
g[x]=1−p[x]−1
当
p
[
x
]
=
1
p[x]=1
p[x]=1时
g
[
x
]
g[x]
g[x]为0
最后
F
M
I
FMI
FMI回来就可以了
#include<bits/stdc++.h>
using namespace std;
const int RLEN=1<<22|1;
inline char gc(){
static char ibuf[RLEN],*ib,*ob;
(ib==ob)&&(ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
return ib==ob?EOF:*ib++;
}
#define gc getchar
inline int read(){
char ch=gc();
int res=0,f=1;
while(!isdigit(ch))f^=ch=='-',ch=gc();
while(isdigit(ch))res=(res+(res<<2)<<1)+(ch^48),ch=gc();
return f?res:-res;
}
const int N=22;
int n,m;
double p[1<<N];
const double eps=1e-8;
inline void FWT(double *f,int kd){
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
if(j&(1<<i))continue;
f[j|(1<<i)]=f[j|(1<<i)]+kd*f[j];
}
}
}
int main(){
n=read(),m=1<<n;
for(int i=0;i<m;i++)scanf("%lf",&p[i]);
FWT(p,1);
for(int i=0;i<m;i++)
p[i]=(1-p[i])>eps?(-1.00/(1.00-p[i])):0;
FWT(p,-1);
if(p[m-1]<eps)puts("INF");
else printf("%.6lf",p[m-1]);
}