HDU 4336——Card Collector——————【概率dp】
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
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.
#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】的更多相关文章
- $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 状态压缩)
Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...
- HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)
题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...
- 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/Othe ...
- [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种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p ...
随机推荐
- AttributeError: ‘module’ object has no attribute ‘ximgproc’(OpenCV)
问题描述: 使用opecv实现选择性搜索(selective search)的时候,执行如下代码时报了上述标题的错误. “ss = cv2.ximgproc.segmentation.createSe ...
- 【bzoj1853】: [Scoi2010]幸运数字 数论-容斥原理
[bzoj1853]: [Scoi2010]幸运数字 预处理出所有幸运数字然后容斥原理 但是幸运数字是2logn个数的 直接搞会炸 所以把成倍数的处理掉 然后发现还是会T 所以数字要从大到小处理会快很 ...
- loj #6250. 「CodePlus 2017 11 月赛」找爸爸
#6250. 「CodePlus 2017 11 月赛」找爸爸 题目描述 小 A 最近一直在找自己的爸爸,用什么办法呢,就是 DNA 比对. 小 A 有一套自己的 DNA 序列比较方法,其最终目标是最 ...
- t-sql read xlsx
How to Read and Load an Excel 2007 or Excel 2010 File Without Using Import/Export Utility To read an ...
- Orcale创建函数(function)
Oraclec创建函数的语法规则 create or replace function 函数名 (参数名1 参数类型,参数名2 参数类型) return number is Result num ...
- P4177 [CEOI2008]order 最小割
\(\color{#0066ff}{ 题目描述 }\) 有N个工作,M种机器,每种机器你可以租或者买过来. 每个工作包括若干道工序,每道工序需要某种机器来完成,你可以通过购买或租用机器来完成. 现在给 ...
- Nginx02---指令集实现静态文件服务器
location 实现静态服务器,就是root和alias命令,他们位于location文件块中,详细:https://www.jianshu.com/p/4be0d5882ec5 root root ...
- Winscp使用密钥登录
Winscp使用密钥登录 背景:通常我们使用winscp通过密码认证去连接服务器进行文件的ftp操作,但是为了安全,我们服务器上经常会禁止使用密码连接,而改用密钥认证.而且服务器上经常会禁止root用 ...
- 74th LeetCode Weekly Contest Number of Subarrays with Bounded Maximum
We are given an array A of positive integers, and two positive integers L and R (L <= R). Return ...
- BestCoder Round #64 1002
Sum Accepts: 322 Submissions: 940 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/655 ...