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. mybatis动态拼接条件的技巧 where 1=1 或者where标签

    /**     * 根据输入的学生信息进行条件检索     * 1. 当只输入用户名时, 使用用户名进行模糊检索:     * 2. 当只输入邮箱时, 使用性别进行完全匹配     * 3. 当用户名 ...

  2. JS权威指南需要注意的知识点(1-6章)

    客官快来看一看了,都给你浓缩好了,确定不进来搂一眼嘛,走过路过不要错过哟 in运算符 in运算符希望它的左操作数是一个字符串或可以转化为字符串,希望它的右操作数是一个对象,如果右侧的对象拥有一个名为左 ...

  3. SqlServer 统计1-12月份 每个月的数据(临时表)

    想做一个年度图表 效果如下,通过sqlserver来统计今年1-12月份每个月的数据,效果如下 sql语句网上找了很多都没有找到满意的 找到的其中一种写法是这样子的 这种写法对于前端来说很方便 不用进 ...

  4. JavaScript之数据类型转换

    JavaScript中有多种数据类型,在实际工作中,不管是有意还是无意的,我们总能碰到不一样的数据类型值之间进行运算,或者我想从用户输入获得一个数字时,而用户却输入了一个字符串,这种时候就需要用到今天 ...

  5. 08.Django基础六之ORM中的锁和事务

    一 锁 行级锁 select_for_update(nowait=False, skip_locked=False) #注意必须用在事务里面,至于如何开启事务,我们看下面的事务一节. 返回一个锁住行直 ...

  6. net core WebApi——定时任务Quartz

    目录 前言 Quartz 测试 问题及解决方法 小结 前言 本来打算昨天都开始写这篇,就因为要把小团队的博客整理汇总,一看二哈的博客那么多,一个个复制粘贴肯定麻烦(其实是我自己觉得复制麻烦),所以穿插 ...

  7. asp.net core IdentityServer4 实现 implicit(隐式许可)实现第三方登录

    前言 OAuth 2.0默认四种授权模式(GrantType) 授权码模式(authorization_code) 简化模式(implicit) 密码模式(resource owner passwor ...

  8. JMeter 压测Server Agent无法监控资源问题,PerfMon Metrics Collector报Waiting for sample,Error loading results file - see file log, Can't accept UDP connections java.net.BindException: Address already in use 各种疑难杂症

    如何安装插件此博主已经说得很详细了. https://www.cnblogs.com/saryli/p/6596647.html 但是需注意几点: 1.修改默认端口,这样可以避免掉一个问题.Serve ...

  9. 深度汉化GCompris-qt,免费的幼儿识字软件

    1 需求 因为有个小孩上幼儿园了,想开始教他一些汉语拼音和基本的汉字,但通过一书本和卡片又有些枯燥乏味,于上就上网搜索一些辅助认字的应用,还购买了悟空识字APP,在用的过程中发现他设置了很严格的关卡, ...

  10. 07-简单认识margin

    margin 外边距,表示边框到最近盒子的距离. 对于左右两边 <!DOCTYPE html> <html lang="en"> <head> ...