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 ...
随机推荐
- 双击获取GridView控件行信息
有网友要求在GridView控件上,不管是单击(onclick)还是双击(ondblclick),想获取所击行的信息.技术难度是为GridView的行注册单击或是双击事件.看例子吧:在数据库中创建数据 ...
- js setTime()详解
来源:http://www.jb51.net/article/35535.htm#t1 setTimeout setTimeout 语法例子 用 setTimeout 来执行 function 不断重 ...
- python3中模块初识
python的模块使用方法 1.用于显示python的环境变量 import sys print(sys.path) 运行路径执行结果如下: ['F:\\codes', 'F:\\codes', 'C ...
- 为所有的Ul下的li标签添加点击事件
- 深入解读Job System(1)
https://mp.weixin.qq.com/s/IY_zmySNrit5H8i0CcTR7Q 通常而言,最好不要把Unity实体组件系统ECS和Job System看作互相独立的部分,要把它们看 ...
- 深入浅出git
图文 http://www.cnblogs.com/syp172654682/p/7689328.html 廖雪峰 https://www.liaoxuefeng.com/wiki/001373951 ...
- 拖放(Drag和Drop)--html5
拖放,就是抓取一个对象后拖放到另一个位置.很常用的一个功能,在还没有html5的时候,我们实现这个功能,通常会用大量的js代码,再利用mousemove,mouseup等鼠标事件来实现,总的来说比较麻 ...
- GIT版本控制系统(二)
貌似第二条有点用,还木有都验证过,贴过来再说~ 转自: http://www.cnblogs.com/lhb25/p/10-useful-advanced-git-commands.html 1. 导 ...
- mysql远程访问被禁止
远程连接Mysql服务器的数据库,错误代码是1130,ERROR 1130: Host xxx.xxx.xxx.xxx is not allowed to connect to this MySQL ...
- Jenkins 相关
手动下载Jenkins plugin 的地址, 下载后的是zip 文件,然后再手动修改为.hpi 文件,然后再手动上传 https://plugins.jenkins.io/