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],可 ...
随机推荐
- ridge regression 无惩罚,导致预测结果空间过大而无实用价值
[ biased regression methods to reduce variance---通过偏回归来减小方差] https://onlinecourses.science.psu.edu/s ...
- Consumer Group Example
面向kafka编程 Consumer Group Example https://cwiki.apache.org/confluence/display/KAFKA/Consumer+Group+Ex ...
- js版本的汉字转拼音
var PinYin = {"a":"\u554a\u963f\u9515","ai":"\u57c3\u6328\u54ce\u ...
- PowerDesigner 125 导致 Word 2007文档内容无法选中以及点击鼠标没用
- LeetCode:访问所有节点的最短路径【847】
LeetCode:访问所有节点的最短路径[847] 题目描述 给出 graph 为有 N 个节点(编号为 0, 1, 2, ..., N-1)的无向连通图. graph.length = N,且只有节 ...
- WINFROM中自定义控件之绑定数据即时更新
相信在WINFROM中写自定义控件或者用户控件,很多人都多多少少用过点 最近发现一个用户控件,绑定的数据源没办法自动更新,其实以前处理过这类的问题,可是这次遇到又花了1个多小时,所以决定记下来 在用户 ...
- 理解SQL原理,写出高效的SQL语句
我们做软件开发的,大部分人都离不开跟数据库打交道,特别是erp开发的,跟数据库打交道更是频繁,存储过程动不动就是上千行,如果数据量大,人员流动大,那么我们还能保证下一段时间系统还能流畅的运行吗?我们还 ...
- IDEAL葵花宝典:java代码开发规范插件 Rainbow Brackets 插件
前言: 最近在Jetbrains IDEA插件网站逛发现了 Rainbow Brackets这款插件,非常棒,推荐给大家. 可以实现配对括号相同颜色,并且实现选中区域代码高亮的功能. 对增强写代码的有 ...
- 改变Ecplise项目窗口字体样式
Eclipse\plugins\org.eclipse.ui.themes_1.1.1.v20151026-1355\css e4-dark_win.css CTabFolder Tree, CTab ...
- win7 jenkins搭建.Net项目自动构建
前提:操作系统win7, 确保需要的.NET Framework已经安装 1. 安装插件 Jenkins--系统管理局--管理插件--可选插件,搜索MSBuild Plugin并安装:重启tomcat ...