题面

传送门

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. (USB HID) Report Descriptor 理解

    在這理整理一下基本 Report Descriptor 對於入門基礎的了解. 在很多文件.Blog都有提到HID report 總共分為3種 : Input.Output.Feature report ...

  2. C# 文件读写Helper类

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.I ...

  3. L1-2 倒数第N个字符串 (15 分)真坑

    给定一个完全由小写英文字母组成的字符串等差递增序列,该序列中的每个字符串的长度固定为 L,从 L 个 a 开始,以 1 为步长递增.例如当 L 为 3 时,序列为 { aaa, aab, aac, . ...

  4. 数组和arguments

    Arguments(Array-Like Objects) arguments对象是所有(非箭头)函数中都可用的局部变量 拥有四个属性(按照规范来说只有三个了----caller) arguments ...

  5. vue项目element-ui框架中的弹窗中的表单验证清除问题

    问题回顾: 1.vue项目的在弹窗上的form表单验证,第一次点击新增时正常,第二次新增打开弹窗后由于表单内容为空,出现验证这种情况 2.为了解决上面的情况,在执行点击新增事件加上this.$refs ...

  6. linux的yum报错

    yum makecache Loaded plugins: fastestmirror Could not retrieve mirrorlist http://mirrorlist.centos.o ...

  7. 补充ABP Zero集成微信小程序登陆的BUG修复部分

    感谢园友 @turingguo 发布的 https://www.cnblogs.com/turingguo/p/9019026.html  文章,详细介绍了ABP Zero集成微信小程序登陆的实现过程 ...

  8. WCF系列教程之初识WCF

    本随笔参考自WCF编程系列(一)初识WCF,纯属读书笔记,加深记忆. 1.简介:Windows Communication Foundation(WCF)是微软为构建面向服务的应用程序所提供的统一编程 ...

  9. 解决JavaScript拖动时同时触发点击事件的BUG

    在做在线地图项目的时候,在给marker点绑定事件时,因为有点击事件click,同时又存在拖动dragEnd事件,首先没有重大缺陷,就是在用户在点击的时候,有时候本想是点击,但是他触发了drag的事件 ...

  10. spring异常被吞的一种情形

    你是否遇到过下面的情况,控制台无限的输出下面的日志: Logging initialized using ‘class org.apache.ibatis.logging.log4j.Log4jImp ...