luoguP3175 [HAOI2015]按位或 min-max容斥 + 高维前缀和
考虑min-max容斥
\(E[max(S)] = \sum \limits_{T \subset S} min(T)\)
\(min(T)\)是可以被表示出来
即所有与\(T\)有交集的数的概率的和的倒数
通过转化一下,可以考虑求所有与\(T\)没有交集的数的概率和
即求\(T\)的补集的子集的概率和
用FMT随意做下吧...
注意:概率为1的时候需要特判
复杂度\(O(2^n * n)\)
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define de double
#define ri register int
#define rep(io, st, ed) for(ri io = st; io <= ed; io ++)
#define drep(io, ed, st) for(ri io = ed; io >= st; io --)
const int sid = (1 << 20) + 25;
int n, show;
de Max, sub[sid];
int main() {
scanf("%d", &n);
rep(i, 0, (1 << n) - 1) {
scanf("%lf", &sub[i]);
show |= i * (sub[i] > 1e-8);
}
if(show != (1 << n) - 1) { puts("INF"); return 0; }
rep(i, 1, n) rep(S, 0, (1 << n) - 1)
if(!(S & (1 << i - 1)))
sub[S ^ (1 << i - 1)] += sub[S];
int T = (1 << n) - 1;
rep(S, 1, (1 << n) - 1) { // no 0
if(__builtin_popcount(S) & 1) Max += 1.0 / (1.0 - sub[T ^ S]);
else Max -= 1.0 / (1.0 - sub[T ^ S]);
}
printf("%.12lf\n", Max);
return 0;
}
喵喵喵?喵喵喵! 喵喵喵......