HDU 4336 Card Collector(动态规划-概率DP)
Card Collector
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.
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.
You will get accepted if the difference between your answer and the standard answer is no more that 10^-4.
1
0.1
2
0.1 0.4
10.000
10.500
题目大意:
有n个卡片,你如今买一包方便面,没包方便面出现当中一个卡片的概率为 p[i] 。问你集齐一套卡片须要的张数的数学期望。
解题思路:
概率DP,用位进制0表示这个卡片有了,1表示这个卡片还没有。那么 比如 “3” 用二进制表示 “1 1” 那么 数组 dp[3] 记录的就是 1号卡片和2号卡片都有的情况集齐一套卡片须要的张数的数学期望。
dp[sum]= ( 1+sum { dp[ sum + (1<<j )] *p[j] } ) /sum{p[j] }
当中 ( i&(1<<j) )==0
解题代码:
#include <iostream>
#include <cstdio>
using namespace std; const int maxn=(1<<20)+10;
int n;
double dp[maxn];
double p[30]; void solve(){
int sum=(1<<n)-1;
dp[sum]=0;
for(int i=sum-1;i>=0;i--){
double tmp=0;
dp[i]=1;
for(int j=0;j<n;j++){
if( ( i&(1<<j) )==0 ){
dp[i]+=dp[i+(1<<j)]*p[j];
tmp+=p[j];
}
}
dp[i]/=tmp;
}
printf("%lf\n",dp[0]);
} int main(){
while(scanf("%d",&n)!=EOF){
for(int i=0;i<n;i++) scanf("%lf",&p[i]);
solve();
}
return 0;
}
HDU 4336 Card Collector(动态规划-概率DP)的更多相关文章
- 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 (概率dp+位运算 求期望)
题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 4336 Card Collector:期望dp + 状压
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 一共有n种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p ...
- hdu 4336 Card Collector(状压dp/Min-Max反演)
传送门 解题思路 第一种方法是状压\(dp\),设\(f(S)\)为状态\(S\)到取完的期望步数,那么\(f(S)\)可以被自己转移到,还可以被\(f(S|(1<<i))\)转移到,\( ...
- HDU 4336 Card Collector 期望dp+状压
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...
- HDU 4050 wolf5x(动态规划-概率DP)
wolf5x Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
- $HDU$ 4336 $Card\ Collector$ 概率$dp$/$Min-Max$容斥
正解:期望 解题报告: 传送门! 先放下题意,,,已知有总共有$n$张卡片,每次有$p_i$的概率抽到第$i$张卡,求买所有卡的期望次数 $umm$看到期望自然而然想$dp$? 再一看,哇,$n\le ...
- HDU 4336 Card Collector(状压 + 概率DP 期望)题解
题意:每包干脆面可能开出卡或者什么都没有,一共n种卡,每种卡每包爆率pi,问收齐n种卡的期望 思路:期望求解公式为:$E(x) = \sum_{i=1}^{k}pi * xi + (1 - \sum_ ...
随机推荐
- Ubuntu 15.04 Rails4.2.5 处理异常
1. 修改: /app/controllers/application_controller.rb文件为如下样子: class ApplicationController < ActionCon ...
- Spring AOP基于xml配置实例
SpringAOP里的几个术语,什么切面,切点之类的,官方的说明太抽象.为了更好地理解记忆,这里几下我自己的通俗的理解. 切面:就是日记类,什么前置通知后置通知(这些都是所谓的Advice)的具体方法 ...
- Recursive Depth first search graph(adj matrix)
1 深度优先遍历邻接矩阵 1 邻接矩阵初始化 2 访问数组初始化 3 深度优先遍历邻接矩阵图 算法如下: bool MGraph[128][128]; bool visit[128]; int vex ...
- 【转】页面尺寸不一样的PDF页面调整方法
本文综合参考:http://www.360doc.com/content/10/1114/22/2961363_69395272.shtml http://blog.sina.com.cn/s/blo ...
- java.lang.ClassNotFoundException: javax.servlet.Filter
java.lang.ClassNotFoundException: javax.servlet.Filter:有两个原因:(1)在maven中的作用域,不能是provided,需要是compile就是 ...
- perl学习(2) 基本数据类型等
1.1.数字 所有数字格式内部一致,全部是double 7.25e45 == 7.25 * 1045 5.25 6.00 5.1-2.4 #5.1-2.4,2.7 10/3 ...
- 深入探究VC —— 编译器cl.exe(1)
cl.exe的功能是将源代码文件编译为可提供链接器使用的obj对象文件.cl.exe命令行参数形式如下: CL (option...) file... [option | file]... [lib. ...
- JAX-RS
一.简介 JAX-RS(Java API for RESTful Web Services),是JAVAEE6中提出的Java 编程语言的应用程序接口,支持按照表述性状态转移(REST)架构风格创建W ...
- 第四种:GCD
GCD 1> 概述 Grand Central Dispatch (GCD)是Apple开发的一种多核编程技术.主要用于优化应用程序以支持多核处理器以及其他对称多处理系统. GCD提供函数实现多 ...
- POJ 1410 Intersection(线段相交&&推断点在矩形内&&坑爹)
Intersection 大意:给你一条线段,给你一个矩形,问是否相交. 相交:线段全然在矩形内部算相交:线段与矩形随意一条边不规范相交算相交. 思路:知道详细的相交规则之后题事实上是不难的,可是还有 ...