Card Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 3407    Accepted Submission(s): 1665
Special Judge

Problem Description
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.

 
Input
The first line of each test case contains one integer N (1 <= N <= 20), indicating the number of different cards you need the collect. The second line contains N numbers p1, p2, ..., pN, (p1 + p2 + ... + pN <= 1), indicating the possibility of each card to appear in a bag of snacks.

Note there is at most one card in a bag of snacks. And it is possible that there is nothing in the bag.

 
Output
Output one number for each test case, indicating the expected number of bags to buy to collect all the N different cards.

You will get accepted if the difference between your answer and the standard answer is no more that 10^-4.

 
Sample Input
1
0.1
2
0.1 0.4
 
Sample Output
10.000
10.500
 
Source
 
 
题目大意:要收集方便面中的人物卡片,n是要收集n种卡片,下面给n种卡片的出现概率,问你收集全n种卡片的期望值。
 
解题思路:概率dp。
 
#include<bits/stdc++.h>
using namespace std;
const int maxn=1<<21;
double dp[maxn];
double p[21];
int main(){
int n;
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++)
scanf("%lf",&p[i]);
dp[(1<<n)-1]=0;
for(int s=(1<<n)-2;s>=0;s--){
double sum=1.0,sump=0;
for(int j=0;j<n;j++){
if(!((1<<j)&s)){
sum+=dp[s|(1<<j)]*p[j];
sump+=p[j];
}
}
dp[s]=sum/sump;
}
cout<<dp[0]<<"++++"<<endl;
printf("%.5f\n",dp[0]);
}
return 0;
}

  

HDU 4336——Card Collector——————【概率dp】的更多相关文章

  1. $HDU$ 4336 $Card\ Collector$ 概率$dp$/$Min-Max$容斥

    正解:期望 解题报告: 传送门! 先放下题意,,,已知有总共有$n$张卡片,每次有$p_i$的概率抽到第$i$张卡,求买所有卡的期望次数 $umm$看到期望自然而然想$dp$? 再一看,哇,$n\le ...

  2. HDU 4336 Card Collector 期望dp+状压

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...

  3. hdu 4336 Card Collector(期望 dp 状态压缩)

    Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...

  4. HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...

  5. HDU 4336 Card Collector(动态规划-概率DP)

    Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...

  6. hdu 4336 Card Collector (概率dp+位运算 求期望)

    题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  7. [HDU 4336] Card Collector (状态压缩概率dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...

  8. HDU 4336 Card Collector(状压 + 概率DP 期望)题解

    题意:每包干脆面可能开出卡或者什么都没有,一共n种卡,每种卡每包爆率pi,问收齐n种卡的期望 思路:期望求解公式为:$E(x) = \sum_{i=1}^{k}pi * xi + (1 - \sum_ ...

  9. HDU 4336 Card Collector:期望dp + 状压

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 一共有n种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p ...

随机推荐

  1. 移动端自适应个人理解与收集——rem

    rem——更好的适配移动端.这个单位我一直想弄个究竟,今天终于看了个差不多.看了很多的博客.心中总算有自己的想法.(还有vh,vw这里我这个小白还没有弄明白就先不写了.) 1.rem可以在html,b ...

  2. Html再学

    1.  Html是网页的载体.内容就是网页制作者放在页面上想要用户浏览的信息,可以包括文字.图片.视频等. 2.  CSS样式是展现.就像网页的外衣.比如,标题字体.颜色变化,或为标题加入背景图片.边 ...

  3. django2集成DjangoUeditor富文本编辑器

    富文本编辑器,在web开发中可以说是不可缺少的.django并没有自带富文本编辑器,因此我们需要自己集成,在这里推荐大家使用DjangoUeditor,因为DjangoUeditor封装了我们需要的一 ...

  4. Tarjan+LCA【洛谷P2783】 有机化学之神偶尔会做作弊

    [洛谷P2783] 有机化学之神偶尔会做作弊 题目背景 XS中学化学竞赛组教练是一个酷爱炉石的人. 有一天他一边搓炉石一边监考,而你作为一个信息竞赛的大神也来凑热闹. 然而你的化竞基友却向你求助了. ...

  5. 将已有项目同步到远程git仓库(github,gitee)及giteee的visual studio插件使用一二

    一.将已有项目同步到远程仓库的最简便方法是用git bash: 将已有项目同步到远程仓库有两种方法:1用git bash:2.用vs插件,两者的思路和步骤基本一致的. 实验发现,如果用vs插件,bas ...

  6. Linux下的hosts文件和network文件区别

    Linux下的hosts文件和network文件区别   Linux下有两种与计算机名相关的配置文件     1.hosts文件,路径:/etc/hosts,此文间是在网络上使用的, 用于解析计算机名 ...

  7. 合并queryset

    今天在实现搜索时遇到一个问题,如何同时搜索model里面的title以及content和category字典 contents = Blog.objects.filter(content__conta ...

  8. gitflow工作流简介

    gitflow工作流是一种依赖于Git版本管理工具,按特定规范对项目开发.测试.上线流程进行管理的工作方式.它是一种为实现规范化管理的约定,它明确了各个分支的意义,使整个团队的分工协作更加和谐明晰. ...

  9. 需要提升权限才能运行dism

    利用系统安装盘来安装.net3.5时,遇到的问题. [命令] dism.exe /online /enable-feature /featurename:NetFX3 /Source:F:\sourc ...

  10. Educational Codeforces Round 7 B

    Description You are given the current time in 24-hour format hh:mm. Find and print the time after a  ...