题目链接

Card Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2711    Accepted Submission(s): 1277
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

题意:

有N(1<=N<=20)张卡片,每包中含有这些卡片的概率为p1,p2,````pN.
每包至多一张卡片,可能没有卡片。
求需要买多少包才能拿到所以的N张卡片,求次数的期望。

分析:

n为20,2^20 = 1 048 576;

所以可以用每一位来表示这种卡片有没有存在,还是逆推。

逆推公式:

d[i] = 1.0 + d[i]*p2 + d[i | (1<<j)]*p[j];

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <algorithm>
#define LL __int64
const int maxn = (<<) + ;
using namespace std;
double d[maxn], p[]; int main()
{
int n, i, j;
double sum, tmp;
while(~scanf("%d", &n))
{
memset(d, , sizeof(d));
sum = ;
for(i = ; i < n; i++)
{
scanf("%lf", &p[i]);
sum += p[i];
}
tmp = 1.0-sum;
d[(<<n)-] = ;
for(i = (<<n)-; i >= ; i--)
{
double p2 = tmp, p3 = ;
for(j = ; j < n; j++)
{
if(i&(<<j))
p2 += p[j]; //p2表示没有抽到新的卡片的概率和
else
p3 += p[j] * d[i|(<<j)];
}
d[i] += (1.0+p3)/(1.0-p2);
}
printf("%.4lf\n", d[]);
}
return ;
}

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)

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

  4. HDU 4336——Card Collector——————【概率dp】

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

  5. HDU - 4336:Card Collector(min-max容斥求期望)

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

  6. sgu 495. Kids and Prizes (简单概率dp 正推求期望)

    题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...

  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种卡片(n <= 20). 对于每一包方便面,里面有卡片i的概率为p[i],可 ...

随机推荐

  1. The template root requires exactly one element

    The template root requires exactly one element

  2. spring 配置bean-自己主动装配

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/qilixiang012/article/details/28260477 概要:(蓝色为本节所讲) ...

  3. Nginx报出504 Gateway Timeout错误2

    昨天,一个程序需要导出500条数据,结果发现到150条是,Nginx报出504 Gateway Timeout错误 经观察,发现大约30秒时超时,php.ini中执行时间配置已经是300秒: 复制代码 ...

  4. [2017-12-20]ElasticSearch 小记

    介绍 ElasticSearch是一款搜索引擎中间件,因其强大的全文索引.查询统计能力和非常方便的全套基于Restful的接口,以及在自动分片.无停机升级扩容.故障转移等运维方面的高效性,逐渐成为中小 ...

  5. [2017-11-21]Abp系列——T4应用:权限树定义

    本系列目录:Abp介绍和经验分享-目录 今天介绍下,如何使用T4根据json文件自动生成权限定义. 先看成果 成果是: 要新增一个权限定义时,打开Json文件,找到目标节点,加个权限定义: 生成下Co ...

  6. Google IO 2019 Android 太长不看版

    Google I/O 2019, 这里有个playlist是所有Android开发相关的session视频合集: Android & Play at Google I/O 2019 当然啦每个 ...

  7. media server died的解决方法【转】

    本文转载自:https://blog.csdn.net/class_brick/article/details/78086261 在对MediaRecord进行初始化时添加上 mMediaRecord ...

  8. Contiki进程间的交互

    之前都是从各个模块开始看起,从底层开始看起.应该改变一下思路,从高往下看,站得高看得远. 一.Main函数 源码:contiki-release-2-7\platform\stm32test\cont ...

  9. java.sql.SQLException: Access denied for user 'somebody'@'localhost' (using password: YES)

    用mybatis和spring整合时出现了一个错误: 我是在IntelliJ IDEA上整合Mybatis和Spring的,运行测试用例出现了如上错误. 红色的马赛克部分是我的名字. 问题是,我的数据 ...

  10. Java截取最后一个 _ 后面的所有字符

    String file = http://localhost:8888/upload/20190310/115111_58_592_HDFS读取文件的流程.png //截取文件名 String ori ...