Card Collector

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5254    Accepted Submission(s): 2676
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 
 

Statistic | Submit | Discuss | Note

首先状压DP很显然,就是$f_S=\frac{1+\sum_{i\subseteq S}p_i f_{S\cup i}}{1-\sum_{i\subseteq S}p_i}$

时间$O(2^n*n)$,空间$O(2^n)$。

引入最值反演:$\max\{S\}=\sum_{T\subseteq S}(-1)^{|T|+1}min\{T\}$。

这个式子里的$\max\{S\}$可以表示集合中最大的数,也可以表示集合中最后一个出现的数(因为按照出现顺序标号就成了求最大数了)。

min-max容斥其实就是最值反演,考虑这样一类问题,每个元素有出现概率,求某个集合最后一个出现的元素所需次数的期望。

$E[\max\{S\}]=\sum_{T\subseteq S}(-1)^{|T|+1}E[min\{T\}]$

考虑$E[min\{T\}]$怎么求,实际上就是求集合中出现任意一个元素的概率的倒数,也就是$\frac{1}{\sum_{i\in T}p_i}$

这样只需枚举全集的子集即可。复杂度优化很多。

时间$O(2^n)$,空间$O(n)$。

 #include<cstdio>
#include<algorithm>
#define rep(i,l,r) for (int i=l; i<=r; i++)
typedef double db;
using namespace std; const int N=;
const db eps=1e-;
db a[N],ans;
int n; void dfs(int x,db sum,int k){
if (x>n) { if (sum>=eps) ans+=(db)k/sum; return; }
dfs(x+,sum,k); dfs(x+,sum+a[x],-k);
} int main(){
while (~scanf("%d",&n)){
ans=; rep(i,,n) scanf("%lf",&a[i]);
dfs(,,-); printf("%.10lf\n",ans);
}
return ;
}

[HDU4336]Card Collector(min-max容斥,最值反演)的更多相关文章

  1. 【HDU4336】Card Collector(Min-Max容斥)

    [HDU4336]Card Collector(Min-Max容斥) 题面 Vjudge 题解 原来似乎写过一种状压的做法,然后空间复杂度很不优秀. 今天来补一种神奇的方法. 给定集合\(S\),设\ ...

  2. Card Collector(期望+min-max容斥)

    Card Collector(期望+min-max容斥) Card Collector woc居然在毫不知情的情况下写出一个min-max容斥 题意 买一包方便面有几率附赠一张卡,有\(n\)种卡,每 ...

  3. HDU - 4336:Card Collector(min-max容斥求期望)

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

  4. min-max容斥/最值反演及其推广

    设\(S\)是一个集合,\(\max(S)\)和\(\min(S)\)分别表示集合中的最大值与最小值. 那么有如下式子成立: \[\max(S)=\sum_{T \subseteq S}(-1)^{| ...

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

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

  6. hdu4336 Card Collector MinMax 容斥

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

  7. hdu4336 Card Collector 【最值反演】

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

  8. 【题解】HDU4336 Card Collector

    显然,这题有一种很简单的做法即直接状压卡牌的状态并转移期望的次数.但我们现在有一个更加强大的工具——min-max容斥. min-max 容斥(对期望也成立):\(E[max(S)] = \sum_{ ...

  9. hdu4336 Card Collector

    Problem Description In your childhood, do you crazy for collecting the beautiful cards in the snacks ...

随机推荐

  1. 常用模块(shutil copy、压缩、解压)

    作用与功能 主要用于文件的copy,压缩,解压 导入shuitl模块: import shutil copy方法 1 1.shutil.copyfileobj()  打开file1,并copy写入fi ...

  2. selenium启动IE浏览器报错:selenium.common.exceptions.WebDriverException: Message: Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones. Enable Protected Mode mu

    意思是浏览器的保护模式设置不一致所导致 解决方案-->修改IE设置 将所有区域的保护模式勾选去掉即可

  3. eclipse把jar包引入项目的两种方法

    方法一: build path引入jar包 方法二: 把jar包放入lib文件夹 区别: 把jar包放入lib文件夹,以后把程序发给别人,别人可以直接运行而无需再自己添加jar包 总结: 1.有时即使 ...

  4. Ubuntu 安装jdk与tomcat

    1.官网下载jdk,地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ,选择 ...

  5. [转] Linux命令行编辑常用键

    ctrl + a 将光标移动到命令行开头相当于VIM里shift+^ ctrl + e 将光标移动到命令行结尾处相当于VIM里shift+$ ctrl + 方向键左键 光标移动到前一个单词开头 ctr ...

  6. 2017 多校4 Security Check

    2017 多校4 Security Check 题意: 有\(A_i\)和\(B_i\)两个长度为\(n\)的队列过安检,当\(|A_i-B_j|>K\)的时候, \(A_i和B_j\)是可以同 ...

  7. @Transactional(rollbackFor=Exception.class)的作用

    在项目中,@Transactional(rollbackFor=Exception.class),如果类加了这个注解,那么这个类里面的方 法抛出异常,就会回滚,数据库里面的数据也会回滚. 这种设置是因 ...

  8. DB2设置code page(日文943)

    为了便于 DB2 在执行 DB2 命令或语句之后显示错误.警告和指示性消息,必须安装您期望使用的语言的 DB2 消息文件集.因为 DB2 有基于语言分组的不同分发版,您必须验证安装 CD-ROM 上有 ...

  9. VS debug 简记

    近两日使用VS2013 Professional版本调试一个c源文件,过程中发现有几个bug,不知是IDE的问题还是我设置有问题,记在这里 1.下面的程序段A和B,区别只是for是否加花括号(标准C规 ...

  10. VSM and VEM Modules

    Information About Modules Cisco Nexus 1000V manages a data center defined by a VirtualCenter. Each s ...