hdu4336 Card Collector 容斥原理
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 容斥原理的更多相关文章
- hdu4336 Card Collector 状态压缩dp
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- [HDU4336]Card Collector(min-max容斥,最值反演)
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu4336 Card Collector 概率dp(或容斥原理?)
题意: 买东西集齐全套卡片赢大奖.每个包装袋里面有一张卡片或者没有. 已知每种卡片出现的概率 p[i],以及所有的卡片种类的数量 n(1<=n<=20). 问集齐卡片需要买东西的数量的期望 ...
- hdu 4336 Card Collector 容斥原理
读完题目就知道要使用容斥原理做! 下面用的是二进制实现的容斥原理,详见:http://www.cnblogs.com/xin-hua/p/3213050.html 代码如下: #include< ...
- HDU-4336 Card Collector 概率DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:买食品收集n个卡片,每个卡片的概率分别是pi,且Σp[i]<=1,求收集n个卡片需要 ...
- hdu4336 Card Collector
Problem Description In your childhood, do you crazy for collecting the beautiful cards in the snacks ...
- hdu4336 Card Collector 【最值反演】
题目链接 hdu4336 题解 最值反演 也叫做\(min-max\)容斥,在计算期望时有奇效 \[max\{S\} = \sum\limits_{T \in S} (-1)^{|T| + 1}min ...
- hdu4336 Card Collector(概率DP,状态压缩)
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...
- hdu4336 Card Collector MinMax 容斥
题目传送门 https://vjudge.net/problem/HDU-4336 http://acm.hdu.edu.cn/showproblem.php?pid=4336 题解 minmax 容 ...
随机推荐
- linux磁盘管理 文件挂载
文件挂载的概念 根文件系统之外的其他文件要想能够被访问,都必须通过"关联"到根文件系统上的某个系统来实现,此关联操作即为"挂载",此目录即为"挂载点& ...
- 用matlab绘制中国地图
reference:https://jingyan.baidu.com/article/870c6fc36fdacfb03ee4be58.html shp: http://muchong.com/ht ...
- java中String的equals()和 ==
String a=new String("java"); String b=new String("java"); System.out.println(a.e ...
- win8 下面 listen 的队列长度貌似无效了 上c/s 代码 并附截图,有图有真相
#include <WinSock2.h> #include <stdio.h> #include <windows.h> DWORD ServerRoutine( ...
- SharePoint Framework 构建你的第一个web部件(三)
博客地址:http://blog.csdn.net/FoxDave 本篇接上一讲,我们一起来看一下如何部署和测试本地开发的web部件. 在SharePoint中预览web部件 SharePoint ...
- 四则运算 来源:一位热心的网友 http://www.tqcto.com/article/software/336297.html
功能:实现真分数的四则运算 语言:Java 平台:JDK下的eclipse github地址:https://github.com/yeershao/hello-world/commit/9920a ...
- 禁止textarea拉伸
添加css属性: style="resize:none" ;
- 【转】CEF3加载网页---多字节字符集和UNICODE字符集
static char* MBSCToCEF(const char* mbcsStr) { wchar_t* wideStr; char* utf8Str; int charLen; charLen ...
- Sample Credential Providers
Windows Vista Sample Credential Providers Overview Contents Terms of Use Release Notes SampleCre ...
- shell日常实战练习——通过监视用户登陆找到入侵者
#!/usr/bin/bash #用户检测入侵工具 AUTHLOG=/var/log/secure if [[ -n $1 ]];then AUTHLOG=$1 echo "Using Lo ...