[BZOJ4036]按位或

传送门:https://www.lydsy.com/JudgeOnline/problem.php?id=4036

Sol:

FWT+min-max容斥

#include <bits/stdc++.h>
using namespace std;
int N,cnt[1<<20];
double P[1<<20];
double ans;
int main(){
    scanf("%d",&N);
    N=1<<N;
    for (int i=0;i<N;i++)
        scanf("%lf",&P[i]),cnt[i]=cnt[i>>1]+(i&1);
    for (int i=1;i<N;i<<=1)
            for (int p=i<<1,j=0;j<N;j+=p)
                for (int k=0;k<i;k++)
                    P[i+j+k]+=P[j+k];
    for (int i=1;i<N;i++)
        if (1-P[(N-1)^i]>1e-8) ans+=((cnt[i]&1)?1:-1)/(1-P[(N-1)^i]);
    if (ans<1e-10) cout<<"INF";else
        printf("%.10lf",ans);
}
 

 

posted @ 2019-09-09 21:33  si_nian  阅读(152)  评论(0编辑  收藏  举报