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, ...
随机推荐
- Python 调用shell
第一种,os.system("The command you want"). 这个调用相当直接,且是同步进行的,程序需要阻塞并等待返回.返回值是依赖于系统的,直接返回系统的调用返回 ...
- >> 关于计算机有符号数的符号拓展(sign extension)问题
这里首先阐述相关规律, 情况为将位数较少的有符号存储空间中取出数据并放入更大有符号存储空间, 如: char → short . 规律: 将原空间符号位重复填充至新空间剩余位. eg.(负数情况, ...
- MAC OS U 盘制作与安装方法
伴随着 iMac 5K Retina 和新的 Mac mini 等硬件的发布,苹果终于都推出了 OS X Yosemite 系统正式版了!相信很多人都已经用上.不过对于一些不想升级,而是打算「全新安装 ...
- 带分页、过滤条件的DSL
"query": { "bool": { "must_not": { "match_phrase": { "p ...
- mybatis学习笔记一(入门)
昨天看了一下mybatis,学习了一下有很多东西还不懂,但是想把一些知道的记录一下,如有错误请大家多多指点. mybatis它是apche的一个开源项目,它以前的没名字并不是叫mybatis而是叫ib ...
- 如何在无法直接用VS启动代码时如何调试代码
1. 普通情况下对进程Attach就可以调试. 2. 但是在一些情况下直接attach并无法调试,例如安装程序installer, 这样使用如下的调试方法即可调试安装程序. System.Diagno ...
- Asp.Net BulletedList使用及详解
BulletedList使用及详解 文章来源:www.cnblogs.com/xiohao/archive/2013/10/09/3359263.html BulletedList是一个让你轻松在 ...
- NOIP2010-普及组初赛C语言解析
第十六届全国青少年信息学奥林匹克联赛初赛试题 一.单项选择题 (共20题,每题1.5分,共计30分.每题有且仅有一个正确选项.) 1.2E+03表示( D ). A.2.03 B ...
- ansible 判断和循环
标准循环 模式一 - name: add several users user: name={{ item }} state=present groups=wheel with_items: - te ...
- centos 安装cacti监控
CentOS 6下Cacti搭建文档 安装依赖关系 yum -y install mysql-devel httpd php php-pdo php-snmp php-mysql lm_sensors ...