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 容 ...
随机推荐
- U启动安装原版Win7系统教程
1.制作u启动u盘启动盘2.下载原版win7系统镜像并存入u盘启动盘3.硬盘模式更改为ahci模式 第一步: 将准备好的u启动u盘启动盘插在电脑usb接口上,然后重启电脑,在出现开机画面时通过u盘启动 ...
- .net core 之Hangfire任务调度
Hangfire可用作任务调度,类似延迟任务.队列任务.批量任务和定时任务等. 一.nuget Hangfire包 找到Hangfire.AspNetCore和Hangfire.SqlServer包, ...
- ubuntu下修改文件权限
参考:https://www.cnblogs.com/viviwind/archive/2012/08/02/2619451.html 常用方法如下: sudo chmod 600 ××× (只有所有 ...
- put请求
Action(){ int HttpRetCode; //定义一个变量,用于接收HTTP返回的状态码 web_add_header("Session-Id", "a3ff ...
- 7series 逻辑单元理解(更新中)
7series 逻辑单元理解 ug768和ug799文档介绍了7系列芯片中包含的基本逻辑单元,对其中常用的单元,进行下分析. 1.IOBUF单元 (1)真值表 (2)用途 the design e ...
- Thread.join方法的解析(转)
原文链接:https://www.cnblogs.com/huangzejun/p/7908898.html 1. join() 的示例和作用 1.1 示例 1 // 父线程 2 public cla ...
- activiti 插件安装,以及初始化配置
1.安装插件 2.添加pom 3.配置activiti.cfg.xml 4.绘制业务流程图 MyProcess.bpmn 5.加载activiti数据表 6.创建流程 1.安装eclipse acti ...
- 异常 No module named 'numpy.core._multiarray_umath
No module named 'numpy.core._multiarray_umath 解决方法: 1. 可能是由于模型保存时出错,导致模型没有保存成功,此时删掉保存的模型即可 2. numpy版 ...
- 数据结构~trie树(字典树)
1.概述 Trie树,又称字典树,单词查找树或者前缀树,是一种用于快速检索的多叉树结构,如英文字母的字典树是一个26叉树,数字的字典树是一个10叉树. 我理解字典树是看了这位大佬博客.还不了解字典树的 ...
- java语言登陆界面(菜鸟版)
最近在看的Java入门书是<Head First Java>,一本很棒的Java书. 老师要求的程序流程图我没有,之前我们的做法是写完代码再画流程图,我想这样的做法是不对的,流程图应该是在 ...