Problem Description
I used to think I could be anything, but now I know that I couldn't do anything. So I started traveling.

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.

 
Input
The first line contains an integer T, denoting the number of the test cases.

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.

 
Output
For each test cases, output n lines, the i-th line containing the desired probability for the i-th node.

Your answer will be accepted if its absolute error doesn't exceed 1e-5.

 
Sample Input
2
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
 
Sample Output
0.0000000000
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
 
Source
 
 

 
 
题意:n个点,m条边的无向图,你随机的从一个点开始,走k步,问你对于每一个点,它不被经过的概率是多少。
我们这样考虑,一个点不被经过的概率就是1-这个点经过的概率,所以就设f[i][j]为已经走了i步, 不经过x点,走到第j个点的概率。
$\large f[i+1][to]+=\frac{1}{deg[j]}f[i][j]$
于是对于每一个点我们都跑一遍dp。
然后每个点x的答案就是1-∑dp[i][x].
然后 就水过去了
 
 

 
 
#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的更多相关文章

  1. 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 ...

  2. HDU-5001 Walk (概率DP)

    Problem Description I used to think I could be anything, but now I know that I couldn't do anything. ...

  3. python os.walk()

    os.walk()返回三个参数:os.walk(dirpath,dirnames,filenames) for dirpath,dirnames,filenames in os.walk(): 返回d ...

  4. LYDSY模拟赛day1 Walk

    /* 依旧考虑新增 2^20 个点. i 只需要向 i 去掉某一位的 1 的点连边. 这样一来图的边数就被压缩到了 20 · 2^20 + 2n + m,然后 BFS 求出 1 到每个点的最短路即可. ...

  5. How Google TestsSoftware - Crawl, walk, run.

    One of the key ways Google achievesgood results with fewer testers than many companies is that we ra ...

  6. poj[3093]Margaritas On River Walk

    Description One of the more popular activities in San Antonio is to enjoy margaritas in the park alo ...

  7. os.walk()

    os.walk() 方法用于通过在目录树种游走输出在目录中的文件名,向上或者向下. walk()方法语法格式如下: os.walk(top[, topdown=True[, onerror=None[ ...

  8. 精品素材:WALK & RIDE 单页网站模板下载

    今天,很高兴能向大家分享一个响应式的,简约风格的 HTML5 单页网站模板.Walk & Ride 这款单页网站模板是现代风格的网页模板,简洁干净,像素完美,特别适合用于推广移动 APP 应用 ...

  9. 股票投资组合-前进优化方法(Walk forward optimization)

    code{white-space: pre;} pre:not([class]) { background-color: white; }if (window.hljs && docu ...

随机推荐

  1. Hbase 日常运维

    日常维护的命令 1,major_compact 'testtable',通常生产环境会关闭自动major_compact(配置文件中hbase.hregion.majorcompaction设 为0) ...

  2. 世界地图展开图,来自 Simon's World Map

    Simon's World Map 软件下载地址:https://www.dit-dit-dit.com/Blog/PostId/42/simons-world-map

  3. MySQL优化之索引原理(二)

    一,前言 ​ 上一篇内容说到了MySQL存储引擎的相关内容,及数据类型的选择优化.下面再来说说索引的内容,包括对B-Tree和B+Tree两者的区别. 1.1,什么是索引 ​ 索引是存储引擎用于快速找 ...

  4. 手撸基于swoole 的分布式框架 实现分布式调用(20)讲

    最近看的一个swoole的课程,前段时间被邀请的参与的这个课程 比较有特点跟一定的深度,swoole的实战教程一直也不多,结合swoole构建一个新型框架,最后讲解如何实现分布式RPC的调用. 内容听 ...

  5. C++解决最基本的迷宫问题

    问题描述:给定一个最基本的迷宫图,用一个数组表示,值0表示有路,1表示有障碍物,找一条,从矩阵的左上角,到右下角的最短路.求最短路,大家最先想到的可能是用BFS求,本文也是BFS求最短路的. 源代码如 ...

  6. IDEA微服务项目的application.yml没有绿色叶子的解决办法

    1.今天在写微服务项目的时候成功入坑,那么问题是啥呢?接下来和我一起走入bug的世界吧,让我们看看究竟是怎么回事. *问题描述 1.application.yml是灰色的小格子 2.实在难看 *需要解 ...

  7. 深入理解JVM内存分配策略

    理解JVM内存分配策略 三大原则+担保机制 JVM分配内存机制有三大原则和担保机制 具体如下所示: 优先分配到eden区 大对象,直接进入到老年代 长期存活的对象分配到老年代 空间分配担保 对象优先在 ...

  8. unity - TileMap的注意事项

    本文记述了一些在使用Tilemap绘制场景时的需要注意的细节问题. 关于Tilemap的创建及使用本文不做说明,但推荐佳作:Unity中使用Tilemap快速创建2D游戏世界 - feng 本文项目地 ...

  9. (七十五)c#Winform自定义控件-控件水印组件

    前提 入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章. GitHub:https://github.com/kwwwvagaa/NetWinformControl 码云:ht ...

  10. JDBC对Mysql utf8mb4字符集的处理

    写在前面 在开发微信小程序的时候,评论服务模块希望添加上emoji表情,但是emoji表情是4个字节长度的,所以需要进行设置 当前项目是JAVA编写, 使用JDBC连接操作数据库, 如下针对的JDBC ...