http://acm.split.hdu.edu.cn/showproblem.php?pid=4336

Card Collector

Special Judge

Problem Description
 
In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, for example, if you collect all the 108 people in the famous novel Water Margin, you will win an amazing award.

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.

 
Input
 
The first line of each test case contains one integer N (1 <= N <= 20), indicating the number of different cards you need the collect. The second line contains N numbers p1, p2, ..., pN, (p1 + p2 + ... + pN <= 1), indicating the possibility of each card to 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.

 
Output
 
Output one number for each test case, indicating the expected number of bags to buy to collect all the N different cards.

You will get accepted if the difference between your answer and the standard answer is no more that 10^-4.

 
Sample Input
 
1
0.1
2
0.1 0.4
 
Sample Output
 
10.000
10.500
 
题意:要收集N张卡,吃一包方便面得到第i张卡的概率为p[i],问收集N张卡吃的方便面包数的期望。
思路:容斥原理。奇数加偶数减。
 
 #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(容斥原理)的更多相关文章

  1. hdu 4336 Card Collector 容斥原理

    读完题目就知道要使用容斥原理做! 下面用的是二进制实现的容斥原理,详见:http://www.cnblogs.com/xin-hua/p/3213050.html 代码如下: #include< ...

  2. HDU 4336 Card Collector 期望dp+状压

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4336 Card Collector Time Limit: 2000/1000 MS (Java/O ...

  3. HDU 4336 Card Collector(动态规划-概率DP)

    Card Collector Problem Description In your childhood, do you crazy for collecting the beautiful card ...

  4. HDU 4336——Card Collector——————【概率dp】

    Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  5. hdu 4336 Card Collector (概率dp+位运算 求期望)

    题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. HDU 4336 Card Collector 数学期望(容斥原理)

    题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...

  7. [HDU 4336] Card Collector (状态压缩概率dp)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题目大意:有n种卡片,需要吃零食收集,打开零食,出现第i种卡片的概率是p[i],也有可能不出现卡 ...

  8. hdu 4336 Card Collector——最值反演

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 点集中最早出现的元素的期望是 min ,最晚出现的元素的期望是 max :全部出现的期望就是最晚出现 ...

  9. hdu 4336 Card Collector —— Min-Max 容斥

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 bzoj 4036 的简单版,Min-Max 容斥即可. 代码如下: #include<cst ...

  10. HDU 4336 Card Collector:期望dp + 状压

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意: 一共有n种卡片.每买一袋零食,有可能赠送一张卡片,也可能没有. 每一种卡片赠送的概率为p ...

随机推荐

  1. 字符集WideCharToMultiByte

    GDAL C#封装对中文字符转换过程中存在问题. C++封装一个Win32 DLL,采用Unicode字符集.使用标准头文件. https://msdn.microsoft.com/en-us/lib ...

  2. Win32和MFC项目如何输出调试信息到VS的调试窗口

    直接举例说明: Win32项目: #include <Windows.h> OutputDebugString(TEXT("调试信息:MyCircleImpl::~MyCircl ...

  3. UISegment属性

    1.segmentedControlStyle 设置segment的显示样式. typedefNS_ENUM(NSInteger, UISegmentedControlStyle) { UISegme ...

  4. [转]那些年我还不懂:IList,ICollection,IEnumerable,IEnumerator,IQueryable

    1.首先看一个简单的例子 int[] myArray = { 1, 32, 43, 343 }; IEnumerator myie = myArray.GetEnumerator(); myie.Re ...

  5. 重复点击主界面(TabBar)按钮刷新界面--点击状态栏回到顶部

    1.监听按钮点击   2.判断是否是点击的同一个按钮(记录上次点击的按钮)   3.当重复点击相同按钮时,需要获取当前按钮对应控制器刷新界面      3.1 判断是否重复点击按钮,代码写在哪里?   ...

  6. raid0

    RAID0把数据分割之后放在各个硬盘上,同时读写以提升数据带宽其实在固态硬盘还没有大量出现在零售市场中之前,玩家想要大幅度提升硬盘系统的性能,最常用的方法就是组建RAID0系统.原理很简单,就以SAT ...

  7. Python基础(1)python+Eclipse+pydev环境搭建

    编辑器:Python 自带的 IDLE 简单快捷, 学习Python或者编写小型软件的时候.非常有用.         编辑器: Eclipse + pydev插件 1. Eclipse是写JAVA的 ...

  8. C++之路进阶——codevs1285(宠物收养所)

    1285 宠物收养所  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond   题目描述 Description 最近,阿Q开了一间宠物收养所.收养所提供两种服 ...

  9. run()和star()区别

    run()和star()区别 run()-->只是thread类的一个普通方法调用 star()-->用来启动线程,实现多线程运行

  10. 动画--过渡属性 transition-property

    早期在Web中要实现动画效果,都是依赖于JavaScript或Flash来完成.但在CSS3中新增加了一个新的模块transition,它可以通过一些简单的CSS事件来触发元素的外观变化,让效果显得更 ...