HDU 4336:Card Collector(容斥原理)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4336
Card Collector
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 <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std; double p[];
double dp[]; int main()
{
int n;
while(~scanf("%d", &n)) {
for(int i = ; i < n; i++)
scanf("%lf", &p[i]);
double ans = ;
double sum;
int cnt;
for(int i = ; i < ( << n); i++) {
sum = ; cnt = ;
for(int j = ; j < n; j++) {
if(i & ( << j)) {
cnt++;
sum += p[j];
}
}
if(cnt & ) ans += 1.0 / sum;
else ans -= 1.0 / sum;
}
printf("%f\n", ans);
}
return ;
}
HDU 4336:Card Collector(容斥原理)的更多相关文章
- hdu 4336 Card Collector 容斥原理
读完题目就知道要使用容斥原理做! 下面用的是二进制实现的容斥原理,详见:http://www.cnblogs.com/xin-hua/p/3213050.html 代码如下: #include< ...
- 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 (概率dp+位运算 求期望)
题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 4336 Card Collector 数学期望(容斥原理)
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...
- [HDU 4336] Card Collector (状态压缩概率dp)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...
- hdu 4336 Card Collector——最值反演
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 点集中最早出现的元素的期望是 min ,最晚出现的元素的期望是 max :全部出现的期望就是最晚出现 ...
- hdu 4336 Card Collector —— Min-Max 容斥
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 bzoj 4036 的简单版,Min-Max 容斥即可. 代码如下: #include<cst ...
- HDU 4336 Card Collector:期望dp + 状压
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 一共有n种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p ...
随机推荐
- C#读写BitMap及颜色相乘
C#读写BitMap及颜色相乘 private Bitmap ReadBitMapAndMultipy(Bitmap bitmap0) { int x1width = bitmap0.Width; i ...
- AE设置投影而非重投影IGeoDatasetSchemaEdit
AE设置投影而非重投影 读取一个jpg格式的影像,包含jgw文件,这时设置投影.赋值操作. IRasterDataset raster = rasterWsp.OpenRasterDataset(Fi ...
- IDisplayTransformation
IDisplayTransformation Bounds Full extent in world coordinates. The Bounds property controls the ful ...
- UIPikerView的属性
1. numberOfComponents:返回UIPickerView当前的列数 NSInteger num = _pickerView.numberOfComponents; NSLog( ...
- 参数db_ultra_safe
db_ultra_safe参数设置控制保护级别的其它参数的默认值 可以取的值有:off.data_only.data_and_index.默认值是off -off:不影响db_block_checki ...
- HTML语言的一些元素(一)
1)标题的六个等级:<h1>,<h2>,<h3>,<h4>,<h5>,<h6>.如果写了诸如:<h7>等,则作为正文 ...
- 树形dp Anniversary party(HDU1520)
题意:给出一棵树,(上下级关系)每个节点都有一个权值,要求选出一些节点满足这些节点任意连个点都不是直接的上下级关系,可以得到的最大权值是多少? 分析:对于每个点有两个状态选或者不选,用状态数组dp[u ...
- configuring tortoise git and vs code.
Preparation, SSH keygen: $ git config --global user.name "calos" $ git config --global use ...
- jsp页面中的java代码
jsp页面中的java代码 1.jsp表达式 <%= ....%> 只能放置一个变量常量 2. jsp小脚本 <% .... %> java语句,可以插入一些语句 3. ...
- URAL 1002 Phone Numbers(KMP+最短路orDP)
In the present world you frequently meet a lot of call numbers and they are going to be longer and l ...