In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people in the famous novel Water Margin, you will win an amazing award.
As a smart boy, you notice that to win the award, you must buy much more snacks than it seems to be. To convince your friends not to waste money any more, you should find the expected number of snacks one should buy to collect a full suit of cards.
容斥原理
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std; double p[]; int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=;i<=n;++i)scanf("%lf",&p[i]);
double ans=;
for(int i=;i<(<<n);++i){
int bit=;
double tmp=;
for(int j=;j<=n;++j){
if(i&(<<(j-))){
bit++;
tmp+=p[j];
}
}
if(bit%)ans+=1.0/tmp;
else ans-=1.0/tmp;
}
printf("%.10lf\n",ans);
}
return ;
}