[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 ...
随机推荐
- Hadoop常见重要命令行操作及命令作用
关于Hadoop [root@master ~]# hadoop --help Usage: hadoop [--config confdir] COMMANDwhere COMMAND is one ...
- Salesforce学习之路-admin篇
Salesforce是一款非常强大的CRM(Customer Relationship Management)系统,国外企业使用十分频繁,而国内目前仅有几家在使用(当然,国内外企使用的依旧较多),因此 ...
- Python—字符串和常用数据结构
目录 1. 字符串 2. 列表 2.1 列表的增删改查 2.2 列表的切片和排序 2.3 生成式语法 3. 元组 4.集合 5. 字典 5.1 字典的增删改查 5.2 字典的常见操作 序言:这一章我们 ...
- Linux之文件与目录管理
加油!
- Quartz Version=3.0.4.0,Culture=neutral,PublickeyToken=f6b8c98a402cc8a4或它的一个依赖项。找到的程序集清单定义与程序集引用不匹配
报这种错误,就是比对Quartz的版本 ,右击引用的dll,属性查看版本. 一个项目中要一样 或者接口和调用接口的要一样 . 思路:解决这种问题的思路就是比对版本号.有可能是其它的dll,但是思路 ...
- 23种设计模式之模板方法(Template Pattern)
定义一个操作中的算法的骨架,而将一些步骤延迟到子类中.模板方法使得子类可以不改变一个算法的结构即可重定义该算法的某些特定步骤 AbstractClass:抽象类.用来定义算法骨架和原语操作,在这个类里 ...
- Spring 梳理 - WebMvcConfigurerAdapter详解
参考:https://blog.csdn.net/weixin_43453386/article/details/83623242
- springboot系列之01-产生的背景及其优势
未经允许,不得转载 原作者:字母哥博客 本文完整系列出自:springboot深入浅出系列 一.前置说明 本节大纲 spring boot 诞生的背景 Spring boot 改变了什么 Spring ...
- Ubuntu使用vi命令时,不能正常编辑文件,使用方向键时老是出现很多字母解决方案
原因是系统只装了vi,没有装vim.因为vi是不能直接按退格键删除字符的.所以重新装下vim指令即可: # sudo apt-get install vim 重新使用vi命令进行文件编辑.
- Terminal MultipleXer---终端复用器tmux基本使用
Terminal MultipleXer---终端复用器tmux 使用场景:1.scp大文件 2:编译大文件 3:多窗口对比文件 1.安装tmux [root@localhost ~]# yum in ...