题目传送门

https://vjudge.net/problem/HDU-4336

http://acm.hdu.edu.cn/showproblem.php?pid=4336

题解

minmax 容斥模板题。

一个集合 \(S\) 的至少有一个邮票出现的最早时间是 \(\frac 1{\sum\limits_{i\in S} p_i}\)。


时间复杂度 \(O(2^n)\)。

#include<bits/stdc++.h>

#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b, 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b, 1 : 0;} typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii; template<typename I> inline void read(I &x) {
int f = 0, c;
while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
x = c & 15;
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
f ? x = -x : 0;
} #define lowbit(x) ((x) & -(x)) const int N = 20 + 7;
const int NP = (1 << 20) + 7; int n, S;
double p[N], f[NP];
int pcnt[NP]; inline void work() {
S = (1 << n) - 1;
double ans = 0;
for (int s = 1; s <= S; ++s) f[s] = f[s ^ lowbit(s)] + p[std::__lg(lowbit(s)) + 1], pcnt[s] = pcnt[s ^ lowbit(s)] + 1;
for (int s = 1; s <= S; ++s)
if (pcnt[s] & 1) ans += 1 / f[s];
else ans -= 1 / f[s];
printf("%.10lf\n", ans);
} inline void init() {
for (int i = 1; i <= n; ++i) scanf("%lf", &p[i]);
} int main() {
#ifdef hzhkk
freopen("hkk.in", "r", stdin);
#endif
while (~scanf("%d", &n) && n) {
init();
work();
}
fclose(stdin), fclose(stdout);
return 0;
}

hdu4336 Card Collector MinMax 容斥的更多相关文章

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

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

  2. HDU4336:Card Collector(min-max容斥)

    题面 传送门 Sol 方法一 直接状压就好了 # include <bits/stdc++.h> # define RG register # define IL inline # def ...

  3. hdu 4336 Card Collector —— Min-Max 容斥

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4336 bzoj 4036 的简单版,Min-Max 容斥即可. 代码如下: #include<cst ...

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

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

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

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

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

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

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

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

  8. $HDU$ 4336 $Card\ Collector$ 概率$dp$/$Min-Max$容斥

    正解:期望 解题报告: 传送门! 先放下题意,,,已知有总共有$n$张卡片,每次有$p_i$的概率抽到第$i$张卡,求买所有卡的期望次数 $umm$看到期望自然而然想$dp$? 再一看,哇,$n\le ...

  9. [模板] 容斥原理: 二项式反演 / Stirling 反演 / min-max 容斥 / 子集反演 / 莫比乌斯反演

    //待更qwq 反演原理 二项式反演 若 \[g_i=\sum_{j=1}^i {\binom ij} f_j\] , 则有 \[ f_i=\sum_{j=1}^i (-1)^{i-j} {i \ch ...

随机推荐

  1. spring boot整合WebSocket示例

    1.运行环境 开发工具:intellij idea JDK版本:1.8 项目管理工具:Maven 4.0.0 2.GITHUB地址 https://github.com/nbfujx/springBo ...

  2. 重写LayoutParams,读取子View自定义属性

    在EasyConstraintLayout内部定义一个静态类LayoutParams继承ConstraintLayout.LayoutParams,然后在构造方法中读取上面自定义的属性.我们通过裁剪的 ...

  3. 电脑如何连接windows server服务器

    第一步:win+r 启动‘运行’,输入mstsc 第二步:连接远程桌面,输入服务器ip 第三步,输入账户密码,登陆即可. 注释:mstsc,全称 Microsoft Telnet Screen Con ...

  4. Linux学习篇(四)-Linux 文件管理命令详解

    rootfs:根文件系统,Root FileSystem 的简称. Linux 文件命名规则 长度不超过255个字符. 不能使用/当文件名. 严格区分大小写. Linux 目录简介 / 根目录 /bo ...

  5. 制作自己的win7系统

    每次安装完纯净版的系统,然后是漫长的打补丁,装驱动,装软件.不妨制作一个自己的系统光盘(也就是GHOST系统),再要重装系统时,直接用这个系统光盘,一键安装,方便省时. 制作GHOST系统,就是将本地 ...

  6. mysql-M-S-S模型 中继器 级联

    1.基础环境 三台虚机并且安装有mysql 并且同步好数据库 2.主服务器-创建账号并授权 mysql> create user 'mslave'@'X.X.X.X' identified by ...

  7. Logistic Regression Algorithm解决分类问题

    在线性回归算法中,我们看到,在training set中,输入矩阵X与向量y的值都是连续的.所以在二维空间中,我们可以用一条直线去模拟X与y的变化关系,寻找参数向量theta的取值.如根据房屋面积预测 ...

  8. ELK日志分析系统之logstash7.x最新版安装与配置

    2 .Logstash的简介 2.1 logstash 介绍 LogStash由JRuby语言编写,基于消息(message-based)的简单架构,并运行在Java虚拟机(JVM)上.不同于分离的代 ...

  9. Netty之大名鼎鼎的EventLoop

    EventLoopGroup 与Reactor: 前面的章节中我们已经知道了,一个Netty 程序启动时,至少要指定一个EventLoopGroup(如果使用到的是NIO,通常是指NioEventLo ...

  10. mybatis报错:org.apache.ibatis.builder.BuilderException:Encountered " "shr" "shr " " at line 1,column 1

    程序报错如下: 解决:变量名冲突 表字段‘审核人’简称为shr,与mybatis的OGNL表达式发生冲突. 解决方法:修改冲突的变量名即可. 总结了一下变量命名可能发生冲突的变量集合: bor(字符| ...