首页 技术 正文
技术 2022年11月9日
0 收藏 743 点赞 3,551 浏览 1208 个字

传送门


套路题

看到\(n \leq 20\),又看到我们求的是最后出现的位置出现的时间的期望,也就是集合中最大值的期望,考虑min-max容斥。

由\(E(max(S)) = \sum\limits_{T \subset S} (-1)^{|T| + 1} E(min(T))\),我们要求的就是一个集合至少有一个数字出现的期望时间。那么\(E(min(T)) = \frac{1}{\sum\limits_{S' \cap T \neq \emptyset} p_{S'}}\)。

\(\sum\limits_{S' \cap T \neq \emptyset} p_{S'}\)不是很好求,考虑反过来求。它等于\(1 – \sum\limits_{S' \cap T = \emptyset} p_{S'} = 1 – \sum\limits_{S' \subset (2^N – 1 – T)}p_{S'}\),而$ \sum\limits_{S’ \subset (2^N – 1 – T)}p_{S’}$就是子集和,高维前缀和求解即可。

#include<bits/stdc++.h>#define ld long double//This code is written by Itstusing namespace std;inline int read(){    int a = 0;    char c = getchar();    bool f = 0;    while(!isdigit(c) && c != EOF){        if(c == '-')            f = 1;        c = getchar();    }    if(c == EOF)        exit(0);    while(isdigit(c)){        a = a * 10 + c - 48;        c = getchar();    }    return f ? -a : a;}long double p[1 << 20];int N , cnt1[1 << 20];int main(){#ifndef ONLINE_JUDGE    freopen("in","r",stdin);    freopen("out","w",stdout);#endif    cin >> N;    int all = 0;    for(int i = 0 ; i < 1 << N ; ++i){        cin >> p[i];        cnt1[i] = cnt1[i >> 1] + (i & 1);        if(p[i] > 1e-6)            all |= i;    }    if(all != (1 << N) - 1){        puts("INF");        return 0;    }    for(int i = 0 ; i < N ; ++i)        for(int j = 0 ; j < 1 << N ; ++j)            if(!(j & (1 << i)))                p[j | (1 << i)] += p[j];    ld sum = 0;    for(int i = 0 ; i < 1 << N ; ++i)        if(1 - p[((1 << N) - 1) ^ i] > 1e-7)            sum = sum + (cnt1[i] & 1 ? 1 : -1) / (1 - p[((1 << N) - 1) ^ i]);    cout << fixed << setprecision(6) << sum;    return 0;}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,817
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,900