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. iOS tableView刷新

    下面是我对AFN刷新一个简单的封装我们只需要传过去一个tableView就好了 简化了一些代码 #import <Foundation/Foundation.h> typedef NS_E ...

  2. Chrome浏览器 54 版本显示“Adobe flash player已过期”问题解决

    背景 电脑上面的软件很久没升级,用腾讯电脑管家批量做了一次升级,结果Chrome浏览器升级到54版本flash控件没法用了. 第一时间想到直接到flash官网下载一个新的进行安装,结果官网检测显示,C ...

  3. 了解Java并学会创建Java项目(一个菜鸟的成长历程)

    计算机语言分类:了解 1)低级语言:更接近于计算机的语言 1.1)机器语言:由0和1组成的 1.2)汇编语言:有一些助记符号2)高级语言:更接近于人的语言 2.1)面向过程的:C... 2.2)面向对 ...

  4. 配置HTTPS服务

    环境为CentOS 7.3.httpd2.4.6 一 搭建证书 说明: CA 主机为192.168.29.3 client主机为 192.168.29.100 1 生成私钥 [root@centos7 ...

  5. common js CMD/AMD 是什么 和他们之间的联系区别

    知道JS有模块化开发的说法,也偶尔听过requireJs,AMD,CMD等等名字,甚至使用node的时候,还用过require之类的方法,但是对这些一直没有一个明确的认识和概念.想必这就是许多新手刚接 ...

  6. java服务端和用户端

    1.server Logintherad: package com.zdsofe.server; import java.io.InputStream; import java.io.OutputSt ...

  7. html超级简单实现点赞(收藏)和取消赞效果

    1.前言 我们经常会遇到对一些列表呀进行点赞呀收藏数据等效果呀.今天就用html+css实现超级简单易上手的点赞和取消赞的demo展示. 2.详情 1.css样式 .like{ font-size:6 ...

  8. java对Microsoft Document的操作--->对Excel的操作

    起初,自己想对网站上爬取一些数据来写到Excel表格中,便在网上找了找java操作Excel接口,了解到Apache的POI接口可以对微软的文档进行操作,WIKI搜索的结果如下, HSSF - 提供读 ...

  9. HDU5723 Abandoned country (最小生成树+深搜回溯法)

    Description An abandoned country has n(n≤100000) villages which are numbered from 1 to n. Since aban ...

  10. 由.Net类库提供的农历计算

             由.Net类库提供的农历计算(C#农历)                 2007-11-21 12:47:00 标签:.Net 类库 农历计算 C#农历 休闲            ...