题目传送门

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. iconfont的三种使用方式

    这篇文章主要介绍了iconfont的三种使用方式,需要的朋友可以参考下   在我们项目中经常要使用到iconfont,在此我们使用阿里巴巴矢量库提供的icon图标,此图标库足够为我们提供大量的图标,我 ...

  2. web应用,http协议简介,web框架

    一.web应用 web应用程序是一种可以通过Web访问的应用程序,程序的最大好处是用户很容易访问应用程序,用户只需要有浏览器即可,不需要再安装其他软件.应用程序有两种模式C/S.B/S.C/S是客户端 ...

  3. GIS矢量大数据采集

    1.使用什么工具采集 2.在哪个网站采集 3.采集哪一种数据 >>地理大数据公众号 >>大数据公众号 >>智能数据湖公众号 点.线.面.体 可视化 >> ...

  4. HihoCoder - 1104 Suzhou Adventure (树上背包)

    题目:https://vjudge.net/contest/323605#problem/D 题意:给你一棵n个点的树,1点出发,然后规定k个点必须去,每个点上有一个权值,要走m个点,问最大权值是多少 ...

  5. SQL SERVER 2012文件表(FILETABLE)新体验之一

    SQLSERVER 2012 文件表功能很COOL,让我们体验一下吧. 1,创建数据库 [sql] DREATE DATABASE FileTableTest ON  PRIMARY (     NA ...

  6. thinkphp 级联菜单实现

    养殖场->栋舍级联菜单 //获取默认养殖场和栋舍信息 public function sbjr(){ $yzc_model=M("Yzc"); $list = $yzc_mo ...

  7. 牛客提高D6t2 破碎的序列

    分析 我们不难发现对于偶数的情况只要相邻两个数不相等即可 而对于奇数的情况只要中间恰好隔一个数的两个数不相等即可 于是我们又dp[i][0/1]表示考虑到第i位,这一位和它后面离它最近的一个确定的数是 ...

  8. Flask变量规则(构建动态url)

    原文出处: http://codingdict.com/article/4867 可以通过将可变部分添加到规则参数来动态构建URL.这个变量部分被标记为 < variable-name>. ...

  9. delphi 获取文件的最新修改时间 http://www.delphitop.com/html/wenjian/64.html

    delphi 获取文件的最新修改时间 作者:admin 来源:未知 日期:2010/1/28 13:15:22 人气:1054 标签: QQ空间新浪微博腾讯微博腾讯朋友QQ收藏百度空间百度贴吧更多0 ...

  10. PTA 1067 Sort with Swap(0, i) (贪心)

    题目链接:1067 Sort with Swap(0, i) (25 分) 题意 给定长度为 \(n\) 的排列,如果每次只能把某个数和第 \(0\) 个数交换,那么要使排列是升序的最少需要交换几次. ...