HDU - 4336 Card Collector min-max 容斥
公式:$\max(S)=\sum_{ T\in S} (-1)^{|T|-1} \min(S)$
code:
#include <bits/stdc++.h> #define ll long long #define N 23 #define setIO(s) freopen(s".in","r",stdin) using namespace std; int n; double perc[N],ans; void dfs(int u,double sum,double opt) { if(u==n) { if(sum>1e-9) ans+=opt/sum; return; } dfs(u+1,sum+perc[u+1],opt*-1); dfs(u+1,sum,opt); } int main() { // setIO("input"); while(scanf("%d",&n)!=EOF) { for(int i=1;i<=n;++i) scanf("%lf",&perc[i]); ans=0,dfs(0,0,-1),printf("%.4f\n",ans); } return 0; }