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, ...
随机推荐
- Top 20 JavaScript Projects of 2017
https://www.youtube.com/watch?v=SUMn8y3pi28 20. AngularJS 1 19. Passport 18. Pug 17. Socket.IO 16. J ...
- solr最佳实践
管理页面 页面地址:http://{ip}:{port}/solr/#/ 管理页面的data-import页可以手动重建索引,configuration指定了数据源,重建索引也可以通过http请求触发 ...
- nyoj 79 拦截导弹 (动态规划)
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=79 题意即求最长单调递减子序列 #include<iostream> #inc ...
- [MFC美化] SkinSharp使用详解2-SkinH.h函数介绍
SkinSharp功能强大,该皮肤库支持完全多种颜色改变等. 下面是静态链接库时的SkinH.h头文件: /*在Stdafx.h文件中加入如下语句 #include "SkinH.h&quo ...
- 必须掌握的Linux命令
章节简述: 本章节讲述系统内核.Bash解释器的关系与作用,教给读者如何正确的执行Linux命令以及常见排错方法. 经验丰富的运维人员可以恰当的组合命令与参数,使Linux字符命令更加的灵活且相对减少 ...
- Attempt to write to field 'android.support.v4.app.FragmentManagerImpl android.support.v4.app.Fragment.mFragmentManager' on a null object reference
E/AndroidRuntime﹕ FATAL EXCEPTION: mainProcess: org.example.magnusluca.drawertestapp, PID: 3624java. ...
- Linux下重置MySQL的Root帐号密码
1.停止MySQL服务 /etc/init.d/mysqld stop 2.跳过验证启动MySQL /usr/local/mysql/bin/mysqld_safe --skip-grant-tabl ...
- Dom编程(一)
dom:document object model 文档对象模型 1.事件 body 事件:onload onunload onbeforeunload body.document对象的事件 (1)o ...
- Metrics-Java版的指标度量工具
介绍 Metrics是一个给JAVA服务的各项指标提供度量工具的包,在JAVA代码中嵌入Metrics代码,可以方便的对业务代码的各个指标进行监控,同时,Metrics能够很好的跟Ganlia.Gra ...
- JS 一些常用技巧
记录 JS 常用的技巧 1. 生成随机数 2. 解决浮点数问题 3. 无路可走时,看看是不是 事件 冒泡了...