hdu 4336 Card Collector (概率dp+位运算 求期望)
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
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.
Note there is at most one card in a bag of snacks. And it is possible that there is nothing in the bag.
You will get accepted if the difference between your answer and the standard answer is no more that 10^-4.
0.1
2
0.1 0.4
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+位运算 求期望)的更多相关文章
- $HDU$ 4336 $Card\ Collector$ 概率$dp$/$Min-Max$容斥
正解:期望 解题报告: 传送门! 先放下题意,,,已知有总共有$n$张卡片,每次有$p_i$的概率抽到第$i$张卡,求买所有卡的期望次数 $umm$看到期望自然而然想$dp$? 再一看,哇,$n\le ...
- HDU 4336 Card Collector 期望dp+状压
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...
- HDU 4336 Card Collector(动态规划-概率DP)
Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...
- HDU 4336——Card Collector——————【概率dp】
Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU - 4336:Card Collector(min-max容斥求期望)
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...
- sgu 495. Kids and Prizes (简单概率dp 正推求期望)
题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
- HDU 4336 Card Collector(状压 + 概率DP 期望)题解
题意:每包干脆面可能开出卡或者什么都没有,一共n种卡,每种卡每包爆率pi,问收齐n种卡的期望 思路:期望求解公式为:$E(x) = \sum_{i=1}^{k}pi * xi + (1 - \sum_ ...
- HDU 4336 Card Collector:状压 + 期望dp
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 有n种卡片(n <= 20). 对于每一包方便面,里面有卡片i的概率为p[i],可 ...
随机推荐
- 九度OJ 1163:素数 (素数)
时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:8496 解决:2887 题目描述: 输入一个整数n(2<=n<=10000),要求输出所有从1到这个整数之间(不包括1和这个整数 ...
- 您使用的是不受支持的命令行标记 chrome
检查 chrome://flags/#extensions-on-chrome-urls 是否开启 开启了的话就关掉检查 启动chrome的快捷方式是否在目标后有额外的参数 有就删了 在浏览器中输入c ...
- swift实现AES解密
原来的加密解密是用java写的,用在安卓系统上.现在要用在iOS系统上,所以从服务器上下载过来的加密文件要用swift来实现其的解密方法. 具体过程如下: 给NSData增加一个类目,NSData+A ...
- matplotlib和numpy 学习笔记
1. 在二维坐标系中画一个曲线 import matplotlib.pyplot as plt #data len=400, store int value data = [] #set x,y轴坐标 ...
- (C)程序控制块(TCB)
程序控制块 1. 程序控制块 从代码上看,程序控制块就是一个结构体.例如: typedef struct tcb{ char * tast_name; //任务名字 int p; //任务重要级别 i ...
- P4474 王者之剑
P4474 王者之剑 题目大意 n*m的带权网格,任意选择起点开始时刻为0秒.以下操作,每秒按顺序执行 在第i秒开始的时候,在方格(x,y)上,获得(x,y)的值 在偶数秒,周围四格的值清零 每秒可选 ...
- 调用微信接口token的问题
前言 微信的影响力众所周知,越来越多的人也都离不开它,工作,生活,社交的好帮手.相信大家对微信公众号,小程序也都不陌生,那么在开发公众号,小程序的时候需要调用到微信的接口,固然就会遇到token的问题 ...
- python绘制圆和椭圆
源自:https://blog.csdn.net/petermsh/article/details/78458585 1. 调用包函数绘制圆形Circle和椭圆Ellipse from matplot ...
- Html+CSS3技术实现动画、天气图标动态效果 效果很酷
1. [代码][CSS]代码 <svg version="1.1" id="sun" class="climacon c ...
- BZOJ 2020 [Usaco2010 Jan]Buying Feed,II:贪心【定义价值】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2020 题意: FJ开车去买K份食物. 如果他的车上有X份食物,每走一里就花费X元. FJ的 ...