[HDU5001]Walk
The
nation looks like a connected bidirectional graph, and I am randomly
walking on it. It means when I am at node i, I will travel to an
adjacent node with the same probability in the next step. I will pick up
the start node randomly (each node in the graph has the same
probability.), and travel for d steps, noting that I may go through some
nodes multiple times.
If I miss some sights at a node, it will
make me unhappy. So I wonder for each node, what is the probability that
my path doesn't contain it.
For
each test case, the first line contains 3 integers n, m and d, denoting
the number of vertices, the number of edges and the number of steps
respectively. Then m lines follows, each containing two integers a and
b, denoting there is an edge between node a and node b.
T<=20,
n<=50, n-1<=m<=n*(n-1)/2, 1<=d<=10000. There is no
self-loops or multiple edges in the graph, and the graph is connected.
The nodes are indexed from 1.
Your answer will be accepted if its absolute error doesn't exceed 1e-5.
5 10 100
1 2
2 3
3 4
4 5
1 5
2 4
3 5
2 5
1 4
1 3
10 10 10
1 2
2 3
3 4
4 5
5 6
6 7
7 8
8 9
9 10
4 9
0.0000000000
0.0000000000
0.0000000000
0.0000000000
0.6993317967
0.5864284952
0.4440860821
0.2275896991
0.4294074591
0.4851048742
0.4896018842
0.4525044250
0.3406567483
0.6421630037
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
using namespace std;
#define gc getchar()
inline int read(){
int res=;char ch=gc;
while(!isdigit(ch))ch=gc;
while(isdigit(ch)){res=(res<<)+(res<<)+(ch^);ch=gc;}
return res;
}
#undef gc int T, n, m, K;
struct edge{
int nxt, to;
}ed[];
int head[], cnt;
inline void add(int x, int y)
{
ed[++cnt] = (edge){head[x], y};
head[x] = cnt;
}
int deg[];
double f[][]; inline double DP(int cur)
{
memset(f, , sizeof f);
double res = ;
for (int i = ; i <= n ; i ++) f[][i] = (double)(1.0/(double)n);
for (int j = ; j <= K ; j ++)
{
for (int x = ; x <= n ; x ++)
{
if (x == cur) continue;
for (int i = head[x] ; i ; i = ed[i].nxt)
{
int to = ed[i].to;
f[j+][to] += (double)(f[j][x] / (double)deg[x]);
}
}
res += f[j][cur];
}
return res;
} int main()
{
T = read();
while(T--)
{
memset(head, , sizeof head);
memset(deg, , sizeof deg);
cnt = ;
n = read(), m = read(), K = read();
for (int i = ; i <= m ; i ++)
{
int x = read(), y = read();
add(x, y), add(y, x);
deg[x]++, deg[y]++;
}
for (int i = ; i <= n ; i ++)
printf("%.10lf\n", - DP(i));
}
return ;
}
[HDU5001]Walk的更多相关文章
- hdu5001 Walk 概率DP
I used to think I could be anything, but now I know that I couldn't do anything. So I started travel ...
- HDU-5001 Walk (概率DP)
Problem Description I used to think I could be anything, but now I know that I couldn't do anything. ...
- python os.walk()
os.walk()返回三个参数:os.walk(dirpath,dirnames,filenames) for dirpath,dirnames,filenames in os.walk(): 返回d ...
- LYDSY模拟赛day1 Walk
/* 依旧考虑新增 2^20 个点. i 只需要向 i 去掉某一位的 1 的点连边. 这样一来图的边数就被压缩到了 20 · 2^20 + 2n + m,然后 BFS 求出 1 到每个点的最短路即可. ...
- How Google TestsSoftware - Crawl, walk, run.
One of the key ways Google achievesgood results with fewer testers than many companies is that we ra ...
- poj[3093]Margaritas On River Walk
Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...
- os.walk()
os.walk() 方法用于通过在目录树种游走输出在目录中的文件名,向上或者向下. walk()方法语法格式如下: os.walk(top[, topdown=True[, onerror=None[ ...
- 精品素材:WALK & RIDE 单页网站模板下载
今天,很高兴能向大家分享一个响应式的,简约风格的 HTML5 单页网站模板.Walk & Ride 这款单页网站模板是现代风格的网页模板,简洁干净,像素完美,特别适合用于推广移动 APP 应用 ...
- 股票投资组合-前进优化方法(Walk forward optimization)
code{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && docu ...
随机推荐
- fremark遍历出的li怎么加事件(cforeach循环遍历也同样适用)
遇见这个问题烦了好久好久,网上也没找到答案,琢磨了半天终于找到了方法 1.下面是一个分页信息遍历添加事件,页面跳转 <!-- 分页条信息 --> <div class="c ...
- OPC—— KepServer.ServerState返回值为3和OPCConfig.exe配置文件的根目录
做开发没有对电脑的绝对管理员权限的问题,会出现很多意外,调试OPC是总是连接状态有时莫明返回3,提示 not configuration,问题在于: 没有以管理员权限运行OPCConfig.exe,导 ...
- ZooKeeper 介绍及集群环境搭建
本篇由鄙人学习ZooKeeper亲自整理的一些资料 包括:ZooKeeper的介绍,我们要学习ZooKeeper的话,首先就要知道他是干嘛的对吧. 其次教大家如何去安装这个精巧的智慧品! 相信你能研究 ...
- 利用Jenkins实现项目自动化部署
1.安装Jenkins,参考上一篇博客:安装Jenkins 安装Java 安装tomcat 安装maven 2.全局工具配置,填写好后点击save 3.安装git plugin插件
- (七十二)c#Winform自定义控件-雷达图
前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...
- 黑苹果之DELL台式机安装Mac OS X 10.13.6版本操作系统
由于本人所在的公司一般都是DELL的品牌台式机,所以以DELL台式机做小白鼠.记得在2012年的时候,在当时的那家公司为了学习自学IOS开发的Objective-C开发语言的时候,由于囊中羞涩买不起m ...
- 一台机器上搭建多个redis实例的配置文件修改部分
1.单个redis服务搭建请参考:redis服务搭建 2.一台Redis服务器,分成多个节点,每个节点分配一个端口(6380,6381…),默认端口是6379. 每个节点对应一个Redis配置文件,如 ...
- java基础之循环遍历List和Map
List和Map是在编程中使用的最频繁的集合类型了,每天都不知道要见它们多少面.在这里介绍下这两种类型的循环遍历,以供学习参考和使用. 一.List 遍历List一般有三种方法,如下: List< ...
- Oracle 存储过程判断语句正确写法和时间查询方法
判断语句:if 条件 then if 条件 then ************; elsif 条件 then ************; elsif 条件 then ***** ...
- 函数的return和参数
1.函数 将一些代码进行封装 def 函数名 括号 冒号:#创建 函数体(代码块) 函数名 + 小括号 #调用 1.1函数的返回值 return return 不写返回的是None,return写了不 ...