solution
用(f[i][j])表示第(i)次操作后手上数字为(j)的概率。
那么就有(f[i][j]=sumlimits_{s_1|s_2=j}f[i - 1][s_1] imes p[s_2])
所以第(k)次操作后手上数字为(i)的概率就是(p^k_i)。这里的乘法是集合并卷积。
仍然没有卵用。我们用(FWT)将它转化为点值。
那么第(k)次操作后手上数字为(i)的概率就是(p_i'^k)。这里的乘法就是简单的数乘。
那么手上数组变为(i)的期望次数就是,答案就是(sumlimits_{t=1}^{infty}t (p_i^k-p_i^{k-1})=-(1+p_i+p_i^2+p_i^3+cdots)=frac{1}{x-1})
然后在用(IFWT)转化回去即可。
code
/*
* @Author: wxyww
* @Date: 2020-04-26 08:51:04
* @Last Modified time: 2020-04-26 09:10:07
*/
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#include<ctime>
using namespace std;
typedef long long ll;
const int N = 1 << 21;
ll read() {
ll x = 0,f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1; c = getchar();
}
while(c >= '0' && c <= '9') {
x = x * 10 + c - '0'; c = getchar();
}
return x * f;
}
double a[N];
int main() {
int n = read();
for(int i = 0;i < (1 << n);++i)
scanf("%lf",&a[i]);
for(int i = 0;i < n;++i)
for(int j = 0;j < (1 << n);++j)
if(!((j >> i) & 1))
a[j | (1 << i)] += a[j];
for(int i = 0;i < (1 << n);++i) {
if(a[i] - 1 >= -1e-8) {
if(i == (1 << n) - 1) a[i] = 0;
else {puts("INF");return 0;}
}
else a[i] = 1 / (a[i] - 1);
}
for(int i = 0;i < n;++i)
for(int j = 0;j < (1 << n);++j)
if(!((j >> i) & 1))
a[j | (1 << i)] -= a[j];
printf("%.10lf
",a[(1 << n) - 1]);
return 0;
}
/*
2
0.25 0.25 0.25 0.25
*/