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 ;
}

hdu4336 Card Collector 容斥原理的更多相关文章

  1. hdu4336 Card Collector 状态压缩dp

    Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...

  2. [HDU4336]Card Collector(min-max容斥,最值反演)

    Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. hdu4336 Card Collector 概率dp(或容斥原理?)

    题意: 买东西集齐全套卡片赢大奖.每个包装袋里面有一张卡片或者没有. 已知每种卡片出现的概率 p[i],以及所有的卡片种类的数量 n(1<=n<=20). 问集齐卡片需要买东西的数量的期望 ...

  4. hdu 4336 Card Collector 容斥原理

    读完题目就知道要使用容斥原理做! 下面用的是二进制实现的容斥原理,详见:http://www.cnblogs.com/xin-hua/p/3213050.html 代码如下: #include< ...

  5. HDU-4336 Card Collector 概率DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:买食品收集n个卡片,每个卡片的概率分别是pi,且Σp[i]<=1,求收集n个卡片需要 ...

  6. hdu4336 Card Collector

    Problem Description In your childhood, do you crazy for collecting the beautiful cards in the snacks ...

  7. hdu4336 Card Collector 【最值反演】

    题目链接 hdu4336 题解 最值反演 也叫做\(min-max\)容斥,在计算期望时有奇效 \[max\{S\} = \sum\limits_{T \in S} (-1)^{|T| + 1}min ...

  8. hdu4336 Card Collector(概率DP,状态压缩)

    In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...

  9. hdu4336 Card Collector MinMax 容斥

    题目传送门 https://vjudge.net/problem/HDU-4336 http://acm.hdu.edu.cn/showproblem.php?pid=4336 题解 minmax 容 ...

随机推荐

  1. Debug method

    #define DEBUG(format,...) printf("Ray.he file:"__FILE__" func:%s() line:%d, print &qu ...

  2. chrome console 阻止 Navigated to

    阻止如图 chrome 如图信息

  3. linux操作系统及命令Part 2

    cat 命令 cat .txt .txt .txt > Ta.txt 将左边三个文件纵向合并为Ta文件 cat .txt>> Ta.txt 将左边文件的内容添加到Ta文件中 tar ...

  4. Java反射《二》获取构造器

    package com.study.reflect; import java.lang.reflect.Constructor; import java.lang.reflect.Invocation ...

  5. SpringMVC:后台将List转为Json,传值到页面

    一.JSP页面 <body> <form name="test" action="getAllStudent" method="po ...

  6. (C/C++学习笔记)附页: C/C++各数据类型的相关说明

  7. java泛型讲解

    原文: https://blog.csdn.net/briblue/article/details/76736356 泛型,一个孤独的守门者. 大家可能会有疑问,我为什么叫做泛型是一个守门者.这其实是 ...

  8. 用swagger生成接口文档代码

    1.Swagger2类: package com.example.demo; import com.google.common.base.Predicate; import io.swagger.an ...

  9. .NET界面控件DevExpress发布v18.2.4|附下载

    DevExpress Universal Subscription(又名DevExpress宇宙版或DXperience Universal Suite)是全球使用广泛的.NET用户界面控件套包,De ...

  10. shiro学习(二)身份验证

    身份验证,即在应用中谁能证明他就是他本人.一般提供如他们的身份ID一些标识信息来表明他就是他本人,如提供身份证,用户名/密码来证明. 在shiro中,用户需要提供principals (身份)和cre ...