题面

传送门

Sol

方法一

直接状压就好了

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll; int n;
double p[21], f[1 << 20]; int main(RG int argc, RG char *argv[]){
while(scanf("%d", &n) != EOF){
for(RG int i = 1; i <= n; ++i) scanf("%lf", &p[i]);
RG int S = 1 << n; Fill(f, 0);
for(RG int i = S - 2; ~i; --i){
RG double s = 1.0;
for(RG int j = 1; j <= n; ++j) if(~i & (1 << (j - 1))) s -= p[j];
s = 1.0 - s, f[i] = 1.0 / s;
for(RG int j = 1; j <= n; ++j)
if(~i & (1 << (j - 1))) f[i] += p[j] * f[i | (1 << (j - 1))] / s;
}
printf("%.6lf\n", f[0]);
}
return 0;
}

方法二

方法一实在太水了,显然不是重点

下面介绍一种容斥方法

min-max容斥

\(E[max(S)]=\sum(-1)^{k+1}E[min(S')]\)

其中集合\(S'\subseteq S\),\(k=|S'|\)

\(max(S)\)指的是这个集合内最后出现的元素

\(min(S)\)指的是这个集合内最先出现的元素

\(E\)表示期望第几步出现

具体到这个题

就是要求\(E[max(\)全集\()]\)

\(E[min(S')]\)就是指\(S'\)任意出现一个的期望步数

举例:

每步出现\(x_i\)的概率\(p_i\)

\(min\{x_1, x_2, x_3 \}\)的概率就是\(p_1+p_2+p_3\)

期望步数就是\(\frac{1}{p_1+p_2+p_3}\)

然后就容斥一下这个题

# include <bits/stdc++.h>
# define RG register
# define IL inline
# define Fill(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll; int n;
double p[21], ans; IL void Dfs(RG int x, RG double E, RG int op){
if(x > n){
if(E > 1e-7) ans += 1.0 * op / E;
return;
}
Dfs(x + 1, E, op);
Dfs(x + 1, E + p[x], -op);
} int main(RG int argc, RG char *argv[]){
while(scanf("%d", &n) != EOF){
for(RG int i = 1; i <= n; ++i) scanf("%lf", &p[i]);
ans = 0, Dfs(1, 0, -1);
printf("%.6lf\n", ans);
}
return 0;
}

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. [HDU4336]Card Collector(min-max容斥,最值反演)

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

  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 ...

  10. hdu4336 Card Collector 状态压缩dp

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

随机推荐

  1. Mac 更改/usr/bin 目录权限失败

    对于Mac OS X 10.11 El Capitan用户,由于系统启用了SIP(System Integrity Protection), 导致root用户也没有权限修改/usr/bin目录.按如下 ...

  2. P3994 高速公路

    题目链接 题意分析 这是一道树上斜率优化题 首先 \[dp[i]=min\{dp[j]+(dis[i]-dis[j])* p[i]+q[i]\}(j∈Pre_i)\] 那么就是 \[p[i]=\fra ...

  3. linux中ls命令使用选项

    ls:英文全名:List即列表的意思 -a 列出目录下的所有文件,包括以 . 开头的隐含文件.-b 把文件名中不可输出的字符用反斜杠加字符编号(就象在C语言里一样)的形式列出.-c 输出文件的 i 节 ...

  4. netsh命令操作ipsec

    IPsec就是IP安全筛选,本可以在本地安全策略中的窗口上进行操作添加,那么netsh也可以支持命令行操作这部分的内容. 我们的示例是禁止IP地址为192.168.1.10访问财务部某机3389端口 ...

  5. Python中的range和xrange区别

    range 函数说明:range([start,] stop[, step]),根据start与stop指定的范围以及step设定的步长,生成一个序列. range示例: >>> r ...

  6. springboot(十)-监控应用

    微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台的业务流会经过很多个微服务的处理和传递,出现了异常如何快速定位是哪个环节出现了问题? ...

  7. python学习15-序列化(转载)

    序列化是指把内存里的数据类型转换成字符串,以使其能存储到硬盘或通过网络传输到远程,因为硬盘和网络传输时只能接受bytes 一.pickle 把python对象写入到文件中的一种解决方案,但是写入到文件 ...

  8. centos7 装机配置及 mysql 安装过程

    打开网卡,使操作系统可以上网 1 ip add 查看网卡,lo是回环网卡可以忽略,ens33为实际网卡. [root@localhost ~]# ip add 1: lo: <LOOPBACK, ...

  9. java 接口的学习

    1   什么是接口 接口是一种引用数据类型.使用interface声明接口,形式:  public interface 接口名称{} 1.1.1 接口的特性 [1] 接口中可以声明属性.接口中定义的所 ...

  10. Linux 开机、重启和用户登录注销、用户管理、用户组

    l 关机&重启命令   基本介绍: shutdown –h now 立该进行关机 shudown -h 1 "hello, 1 分钟后会关机了" shutdown –r n ...