bzoj1417: Pku3156 Interconnect
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1417
1417: Pku3156 Interconnect
Time Limit: 10 Sec Memory Limit: 64 MB
Submit: 257 Solved: 133
[Submit][Status][Discuss]
Description
给出无向图G(V, E). 每次操作任意加一条非自环的边(u, v), 每条边的选择是等概率的. 问使得G连通的期望操作次数. (|V| <= 30, |E| <= 1000)
Input
第一行两个整数N,M 1<=N<=30 0<=M<=1000 接下来M行,每行两个整数X,Y表示两者之间已修好一条道路. 两点之间可以不止修了一条路,也有可能M条路已使N个点成为一个整体.
Output
输出一个小数,表示新修道路条数的期望值,保留六位小数.
Sample Input
1 2
3 4
Sample Output
HINT
Source
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
int n,m,all,fa[],size[];
typedef vector<int> pps;
pps v;
map<pps,double>fuckp;
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
double calc(pps ve){
if(fuckp.count(ve))return fuckp[ve];
if(ve.size()==)return fuckp[ve]=;
int s=ve.size();double ss=;
for(int i=;i<s;i++)ss+=ve[i]*(ve[i]-)/;
double p=1.0*all/(all-ss);
for(int i=;i<s;i++)
for(int j=;j<i;j++){
pps b=ve;b[j]+=b[i];swap(b[i],b[s-]);
b.pop_back();sort(b.begin(),b.end());
p+=1.0*ve[i]*ve[j]/(all-ss)*calc(b);
}
return fuckp[ve]=p;
}
int main(){
scanf("%d%d",&n,&m);all=(n-)*n/;
for(int i=;i<=n;i++)fa[i]=i,size[i]=;
for(int i=;i<=m;i++){
int x,y;
scanf("%d%d",&x,&y);
x=find(x);y=find(y);if(x!=y)fa[x]=y,size[y]+=size[x];
}
for(int i=;i<=n;i++)if(fa[i]==i)v.push_back(size[i]);
sort(v.begin(),v.end());
printf("%.6lf\n",calc(v));
return ;
}
bzoj1417: Pku3156 Interconnect的更多相关文章
- 【BZOJ1417】Pku3156 Interconnect 记忆化搜索
[BZOJ1417]Pku3156 Interconnect Description 给出无向图G(V, E). 每次操作任意加一条非自环的边(u, v), 每条边的选择是等概率的. 问使得G连通的期 ...
- 【BZOJ1417】Pku3156 Interconnect
题解: 比较简单的一道题 显然我们只需要知道每个联通块的大小就可以了 然后发现x1+xn=30 其中xi<=xi+1的状态只有5000 所以直接记忆化搜索就可以了 emm原来map还可以映射ve ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- Greenplum记录(一):主体结构、master、segments节点、interconnect、performance monitor
结构:Client--master host--interconnect--segment host 每个节点都是单独的PG数据库,要获得最佳的性能需要对每个节点进行独立优化. master上不包含任 ...
- uva 1390 - Interconnect(期望+哈希+记忆化)
option=com_onlinejudge&Itemid=8&page=show_problem&category=514&problem=4136&mosm ...
- Using an open debug interconnect model to simplify embedded systems design
Using an open debug interconnect model to simplify embedded systems design Tom Cunningham, Freescale ...
- oracle之 RAC Interconnect之HAIP
0. 背景 Oracle 从11.2.0.2开始引入了一个新特性叫做Redundant Interconnect,简称HAIP.HAIP的目的用来代替操作系统级别的网卡绑定以实现Active-Acti ...
- PatentTips - Device virtualization and assignment of interconnect devices
BACKGROUND Standard computer interconnects, particularly for personal computers or workstations, may ...
- PatentTips - Apparatus and method for a generic, extensible and efficient data manager for virtual peripheral component interconnect devices (VPCIDs)
BACKGROUND A single physical platform may be segregated into a plurality of virtual networks. Here, ...
随机推荐
- Node.js调用百度地图Web服务API的Geocoding接口进行点位反地理信息编码
(从我的新浪博客上搬来的,做了一些修改.) 最近迷上了node.js以及JavaScript.现在接到一个活,要解析一个出租车点位数据的地理信息.于是就想到使用Node.js调用百度地图API进行解析 ...
- 关于web多标签多条件筛选的思考以及缓存的正确使用方法(上)
做项目的过程中,发现一次远程链接数据库的耗时大概是300ms~400ms,切身体会到了前辈们经常说的减少链接的重要性,用了缓存后页面的打开时间从1.5s减少到400ms 前提: 那么来说一说正题,we ...
- Java 并发 中断线程
Java 并发 中断线程 @author ixenos 对Runnable.run()方法的三种处置情况 1.在Runnable.run()方法的中间中断它 2.等待该方法到达对cancel标志的测试 ...
- Tip of the Day
Did you know ... ? You can view all statements within the method where certain exceptions can be cau ...
- 使用navicat连接远程linux的mysql中文显示乱码的问题
在navicat对应的连接上 右键->连接属性->高级 去掉使用mysql字符集 然后上面的编码选择 (65001)utf-8 接着打开连接 找到对应的数据库 右键 数据库属性 把编码 ...
- shell 脚本中for循环
昨天很痛苦的搞了一天的for循环,在服务器上运行没啥问题,在设备上运行总是不行,部分代码如下: for(i=1;i<$cnt+1;i++)do echo "xxxx" &g ...
- line-height 行高
line-height 行高指一行文字的高度,具体来说是指两行文子间基线间的距离 line-height 与 font-size 的计算值之差(行距)分为两半,分别加到一个文本行内容的顶部和 ...
- Linked List - leetcode
138. Copy List with Random Pointer //不从head走 前面加一个dummy node 从dummy走先连head 只需记录当前节点 //这样就不需要考虑是先new ...
- cuda编程(一)
环境安装和例程运行 显卡主要有两家,ATI.NVIDIA,简称A卡和N卡.随着GPU计算能力的上升,采用GPU并行计算来加速的应用越来越多. Nvidia创立人之一,黄仁勋(Jen-Hsun Huan ...
- android 音频播放总结 soundlPool,MediaPlay
soundlPool 用于小音频的播放多个同时播放. 使用步骤: 步骤一: 首先下载音频文件可以将其放入assets文件夹下或者res下的raw文件夹下,区别在于assets下可以再新建文件夹二raw ...