概率期望+闭包+bitset优化——hdu5036
我们首先得到:
暴力打开这个箱子,能够开那些箱子。这个可以用bitset来进行状态压缩。
用闭包传递来解决这一步
然后,对于每个箱子,我们考虑有多少种方法,使:暴力打开某些箱子,同时能打开这个箱子。
暴力开这个箱子的期望就是方案数的倒数。然后我们对开每个箱子的期望求和就是最终的打开所有箱子暴力开箱子的数目的期望。
#include<bits/stdc++.h>
using namespace std;
#define maxn 1005
bitset<>e[maxn];
int n,m; void floyd(){
for(int i=;i<=n;i++)//枚举中介点
for(int j=;j<=n;j++)
if(e[j][i]==)
e[j]|=e[i];
} int main(){
int t;cin>>t;
for(int tt=;tt<=t;tt++){
scanf("%d",&n);
for(int i=;i<=n;i++)e[i].reset(); for(int i=;i<=n;i++){
int k,x;scanf("%d",&k);
while(k--){
scanf("%d",&x);
e[i][x]=;
}
e[i][i]=;
} floyd(); double ans=;
for(int i=;i<=n;i++){
double tot=;
for(int j=;j<=n;j++)
if(e[j][i]==)tot+=;
ans+=1.0/tot;
}
printf("Case #%d: %.5lf\n",tt,ans);
}
}
概率期望+闭包+bitset优化——hdu5036的更多相关文章
- hdu 5036 Explosion(概率期望+bitset)
Problem Description Everyone knows Matt enjoys playing games very much. Now, he to N. Input The firs ...
- hdu_5036_Explosion(bitset优化传递闭包)
题目链接:hdu_5036_Explosion 题意: 一个人要打开或者用炸弹砸开所有的门,每个门里面有一些钥匙,一个钥匙对应一个门,有了一个门的钥匙就能打开相应的门,告诉每个门里面有哪些门的钥匙,问 ...
- hdu 5036 Explosion bitset优化floyd
http://acm.hdu.edu.cn/showproblem.php?pid=5036 题意就是给定一副有向图,现在需要走遍这n个顶点,一开始出发的顶点是这n个之中的随便一个. 如果走了1,那么 ...
- 【bzoj5197】[CERC2017]Gambling Guide 期望dp+堆优化Dijkstra
题目描述 给定一张n个点,m条双向边的无向图. 你要从1号点走到n号点.当你位于x点时,你需要花1元钱,等概率随机地买到与x相邻的一个点的票,只有通过票才能走到其它点. 每当完成一次交易时,你可以选择 ...
- 【BZOJ-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
- hdu 5506 GT and set dfs+bitset优化
GT and set Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Probl ...
- hdu 5745 La Vie en rose DP + bitset优化
http://acm.hdu.edu.cn/showproblem.php?pid=5745 这题好劲爆啊.dp容易想,但是要bitset优化,就想不到了. 先放一个tle的dp.复杂度O(n * m ...
- uvalive 7331 Hovering Hornet 半平面交+概率期望
题意:一个骰子在一个人正方形内,蜜蜂在任意一个位置可以出现,问看到点数的期望. 思路:半平面交+概率期望 #include<cstdio> #include<cstring> ...
- OI队内测试一【数论概率期望】
版权声明:未经本人允许,擅自转载,一旦发现将严肃处理,情节严重者,将追究法律责任! 序:代码部分待更[因为在家写博客,代码保存在机房] 测试分数:110 本应分数:160 改完分数:200 T1: 题 ...
随机推荐
- npm转淘宝镜像
1.临时使用 npm --registry https://registry.npm.taobao.org install express 2.持久使用 npm config set registry ...
- Python装饰器使用技巧
装饰器 装饰器是程序开发中经常会用到的一个功能,用好了装饰器,开发效率如虎添翼,所以这也是Python面试中必问的问题,但对于好多初次接触这个知识的人来讲,这个功能有点绕,自学时直接绕过去了,然后面试 ...
- FM算法组合估计
#include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> # ...
- java url中文参数乱码
String city=new String(city_name.getBytes("ISO-8859-1"), "UTF-8");
- 22. Jmeter NON GUI模式
一般情况下我们都是在NonGUI模式下运行jmeter.这样做有两个好处 节省系统资源,能够产生更大的负载 可以通过命令行参数对测试场景进行更精细的配置 需求:模拟5个用户同时访问百度首页的情况 步骤 ...
- pefile解析PE格式
import os,sys import pefile import pydasm import struct #print sys.argv def show_section(pe): print ...
- Gerrit(1): Manage Projects
1) Register an openid account https://login.ubuntu.com/+login 2) Custom settings set SSH pubkey set ...
- 20140808 const和define区别 内联函数(inline) 栈和堆的地址分配 栈帧
1.const和define区别 const有数据类型(不能改变的变量),define只是简单的字符串替换,没有数据类型. C++程序用const完全取代 define. const还可以类成员函数为 ...
- OMG that's another blog!
目录 1.Beginning 2.then 1.Beginning we'v learnt how to ask file from our own computer and tried to bui ...
- python接口自动化(delete请求)
python接口自动化(delete请求) 一.delete请求的目的:删除资源 二.应用 导包:import requests 调用delete方法:requests.delete(url) 获取响 ...