bzoj 4036 [HAOI2015]按位或——min-max容斥+FMT
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=4036
题解:https://www.cnblogs.com/Zinn/p/10260126.html
#include<cstdio> #include<cstring> #include<algorithm> #define db double using namespace std; const int N=25,M=(1<<20)+5; int n,bin[N],lm,ct[M]; db ans,mn[M],p[M];bool vis[N]; void fmt(db *a) { for(int i=1;i<lm;i<<=1) for(int s=0;s<lm;s++) if(s&i)p[s]+=p[s^i]; } int main() { scanf("%d",&n); bin[0]=1;for(int i=1;i<=n;i++)bin[i]=bin[i-1]<<1; lm=bin[n]; for(int s=0;s<lm;s++) { scanf("%lf",&p[s]); if(!p[s])continue; for(int i=0;i<n;i++)if(s&bin[i])vis[i]=1; } for(int i=0;i<n;i++)if(!vis[i]){puts("INF");return 0;} fmt(p); for(int s=1,u=lm-1;s<lm;s++)mn[s]=1/(1-p[u^s]);//s=1//only p[u]=1 for legal for(int s=1;s<lm;s++)ct[s]=ct[s-(s&-s)]+1; for(int s=1;s<lm;s++)//s=1 (ct[s]&1)?ans+=mn[s]:ans-=mn[s]; printf("%.10f\n",ans); return 0; }