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, ...
随机推荐
- java基础<迷你DVD系统>
一.写在main方法中 import java.util.*; public class MyDVDMgr { public static void main(String[] args){ Scan ...
- mysql分享记录
今天公司进行了一次mysql的分享,做一下记录,也许很多东西很简单,但是对于不知道的人就很难 1.用最小代价存储 举个例子来说,如果能确定某个字段是存数字的,并且数字的大小一定不会超过127或255, ...
- Android使用Home键后应用程序重启的问题
正常情况应该是在点击 home 按键后,程序在后台暂停运行,点击 后退键 才会退出应用的,但是今天遇到个问题,点击 home 键后,重新再打开应用却每次都返回应用启动页面,有些莫名其妙,一番googl ...
- wpf xmal基础
1.名称空间的引用 比如想使用System.Windows.Controls名称空间 首先需要把改名称空间所在的程序集presentationFramework.dll引用到项目里 然后在根元素的起始 ...
- Java 并发 线程属性
Java 并发 线程属性 @author ixenos 线程优先级 1.每当线程调度器有机会选择新线程时,首先选择具有较高优先级的线程 2.默认情况下,一个线程继承它的父线程的优先级 当在一个运行的线 ...
- 递归——CPS(三)
JScript不是天然支持CPS,但是可以写一个分发引擎使得能工作在CPS风格下.一般只有一个活动的continuation,所以可以定义规则:JScript CPS 函数允许有返回,但是它们做的最后 ...
- 按键精灵http.定义getWeb
Function 取网页源码(URL) Set objXML=CreateObject("Microsoft.XMLHTTP") objXML.Open "Get&quo ...
- mysql随记
.frm是描述了表的结构,.MYD保存了表的数据记录,*.MYI则是表的索引 ibd是MySQL数据文件.索引文件,无法直接读取. ibdata是innodb引擎使用的 如果是使用myisam引擎 则 ...
- TreeSet与TreeMap的源码分析 JDK7
TreeSet存储原则是:不可重复,有序的. public TreeSet() { this(new TreeMap<E,Object>()); } public TreeSet(Comp ...
- 如何在 Linux 中找出最近或今天被修改的文件
1. 使用 ls 命令,只列出你的 home 文件夹中今天的文件. ls -al --time-style=+%D | grep `date +%D` 其中: -a- 列出所有文件,包括隐藏文件 -l ...