容斥原理+状压

Card Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1940    Accepted Submission(s): 907
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
 
Source
 
Recommend
zhoujiaqi2010   |   We have carefully selected several similar problems for you:  4337 4331 4332 4333 4334 
 
 #include <iostream>
#include <cstdio>
#include <cstring> using namespace std; double p[];
int n; int main()
{
while(scanf("%d",&n)!=EOF)
{
for(int i=;i<n;i++) scanf("%lf",p+i);
double ans=;
for(int i=;i<(<<n);i++)
{
double temp=;
int k=;
for(int j=;j<n;j++)
{
if(i&(<<j))
{
k++;
temp+=p[j];
}
}
ans+=./temp *((k&)?:-);
}
printf("%lf\n",ans);
}
return ;
}

HDOJ 4336 Card Collector的更多相关文章

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

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

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

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

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

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

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

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

  5. 【HDOJ】4336 Card Collector

    概率DP的题目,一直就不会做这类题目.dp[s]表示状态为s的时候再买多少张牌可以买全,表示的是一个期望值.dp[s] = 1 + P(empty) * dp[s] + P(had) * dp[s] ...

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

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

  7. 【HDU】4336 Card Collector

    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 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...

  9. hdu 4336 Card Collector(期望 dp 状态压缩)

    Problem Description In your childhood, people in the famous novel Water Margin, you will win an amaz ...

随机推荐

  1. qt 使用非系统字库

    之前的做法都是把 ttc, ttf 这些文件拷贝到系统字库里去(即拷贝到 lib/fonts 下).但是,每次添加字体,我都要把产品的文件系统都给升级一遍吗?这样系统的一致性就不大好了.所以想能不能直 ...

  2. webbench详解

    安装 mkdir -p /usr/local/man/man1 yum install ctags -y tar zxvf webbench-1.5.tar.gzcd webbench-1.5make ...

  3. C#如何在子窗体获取父窗体的实例

    在子窗体可以使用this.Owner来获取父窗体的实例

  4. hihoCoder #1164 随机斐波那契

    时间限制:5000ms单点时限:1000ms内存限制:256MB描述 大家对斐波那契数列想必都很熟悉: $a_0 = 1, a_1 = 1, a_i = a_{i-1} + a_{i-2}, (i & ...

  5. HTML5系列四(特征检测、Modernizr.js的相关介绍)

    Modernizr:一个HTML5特征检测库 Modernizr帮助我们检测浏览器是否实现了某个特征,如果实现了那么开发人员就可以充分利用这个特征做一些工作 Modernizr是自动运行的,无须调用诸 ...

  6. POJ2528Mayor's posters(离散化 + 线段树)

    题目链接: 题意:给定一些高度都相同的海报去贴,问最后能看见几张海报 The picture below illustrates the case of the sample input. { 8,9 ...

  7. juqery 实现商城循环倒计时

    <html> <hand> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jqu ...

  8. Git / 程序员需要知道的12个Git高级命令

    众所周知,Git目前已经是分布式版本控制领域的翘楚,围绕着Git形成了完整的生态圈.学习Git,首先当然是学习Git的基本工作流.相比于SVN等传统版本控制系统来说,Git是专为分布式版本控制而生的强 ...

  9. C#值类型参数传递的性能开销

    Performance issues Let's dig a little deeper. When data is passed into methods as value type paramet ...

  10. thinkphp连接数据库

    版本:3.1.1 连接数据库的具体位置 thinkphp/Config/convention.php,默认修改数据库在这里就可以了 但是为了方便,把数据库配置写到Index/Conf/config.p ...