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个奖品的概率为ai,求收集齐所有的奖品需要买多少物品的数学期望。
思路:简单第容斥原来。用i表示取奖品第状态,按个数判断加或减
 
 #include<cstdio>

 int main()
{
int n;
double a[];
while (~scanf("%d",&n))
{
for (int i=;i<n;++i)
scanf("%lf",&a[i]);
double temp,ans=;
for (int i=;i< (<<n);++i)
{
temp=;
int ct=;
for (int j=;j<n;++j)
if (i & (<<(j) ) )
{
ct++;
temp+=a[j];
}
if (ct & ) ans+=/temp;
else ans-=/temp;
}
printf("%.4f\n",ans);
}
return ;
}

hdu4336 Card Collector的更多相关文章

  1. hdu4336 Card Collector 状态压缩dp

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

  2. [HDU4336]Card Collector(min-max容斥,最值反演)

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

  3. hdu4336 Card Collector 【最值反演】

    题目链接 hdu4336 题解 最值反演 也叫做\(min-max\)容斥,在计算期望时有奇效 \[max\{S\} = \sum\limits_{T \in S} (-1)^{|T| + 1}min ...

  4. hdu4336 Card Collector(概率DP,状态压缩)

    In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...

  5. hdu4336 Card Collector MinMax 容斥

    题目传送门 https://vjudge.net/problem/HDU-4336 http://acm.hdu.edu.cn/showproblem.php?pid=4336 题解 minmax 容 ...

  6. hdu4336 Card Collector 概率dp(或容斥原理?)

    题意: 买东西集齐全套卡片赢大奖.每个包装袋里面有一张卡片或者没有. 已知每种卡片出现的概率 p[i],以及所有的卡片种类的数量 n(1<=n<=20). 问集齐卡片需要买东西的数量的期望 ...

  7. HDU-4336 Card Collector 概率DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意:买食品收集n个卡片,每个卡片的概率分别是pi,且Σp[i]<=1,求收集n个卡片需要 ...

  8. hdu4336 Card Collector 容斥原理

    In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...

  9. HDU4336 Card Collector(期望 状压 MinMax容斥)

    题意 题目链接 \(N\)个物品,每次得到第\(i\)个物品的概率为\(p_i\),而且有可能什么也得不到,问期望多少次能收集到全部\(N\)个物品 Sol 最直观的做法是直接状压,设\(f[sta] ...

随机推荐

  1. 51nod_1627:瞬间移动

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1627 还是杨辉三角~ #include<bits/st ...

  2. dotpeek的导出

    在开始写之前先说明下,搜了很久的度娘,就是没找到dotpeek的导出功能,····,看来用的人不多, ------------------------------------------------- ...

  3. (转)java提高篇(一)-----理解java的三大特性之封装

    从大二接触java开始,到现在也差不多三个年头了.从最基础的HTML.CSS到最后的SSH自己都是一步一个脚印走出来的,其中开心过.失落过.寂寞过.虽然是半道出家但是经过自己的努力也算是完成了“学业” ...

  4. 初学者:浅谈web前端就业的学习路线

    初级前端 主要学习三个部分:HTML,CSS,JavaScript 一.html + css部分: 这部分特别简单,到网上搜资料,书籍视频非常多.css中盒子模型,流动,block,inline,层叠 ...

  5. perl的安装和版本切换工具-perlbrew

    setenv PERL /opt/perl5 --设置新perl的起始安装路径 curl -kL http://install.perlbrew.pl | bash source /opt/perl5 ...

  6. 解决 lispbox macOS 不兼容问题

    误打误撞,解决了很重要的入门级问题,简要记录下. lispbox 官网末尾说目前暂不兼容 10.4 以上系统: TODO: Compile on Mac OS X 10.4, for compatab ...

  7. Js 获取时间戳

    //获取时间戳 单位:秒: //1. 获取当前时间戳 function getUnixTime(){ var date = new Date(); //使用getTime方法: var unix_ti ...

  8. 带着SMART原则重新出发

    很久以来,对分布式系统都比较感兴趣,但工作中却接触不到,“虽不能至,心向往之”,于是打算自己学.分布式系统领域概念很多,错综复杂,一些理论也比较难以理解,要想学习的话还是得下一番功夫.于是在来两个月前 ...

  9. Section 1.1 Greedy Gift Givers

    Greedy Gift Givers A group of NP (2 ≤ NP ≤ 10) uniquely named friends hasdecided to exchange gifts o ...

  10. 怎样做才是最优雅方式切换 web 项目数据源 ?

    随着业务变迁/需求变更,JavaEE 应用中会被迫连接多个数据源进行业务处理. 怎样在不影响原有项目结构的情况下,已最优雅/最简洁的方式动态切换数据源呢? 本文已一次添加数据源后动态切换实践为例,描述 ...