Walk

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5001

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

HINT

题意

随机走d步,请问没有经过i点的概率是多少

题解:

数据范围很小咯,点很少,那就直接暴力DP就好了

dp[i][j][k]表示没有经过k点,走了i步,现在在j点的位置

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200500
#define mod 1001
#define eps 1e-9
#define pi 3.1415926
int Num;
//const int inf=0x7fffffff;
const ll inf=;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************* vector<int> E[maxn];
double dp[][];
int main()
{
int t = read();
while(t--)
{
int n=read(),m=read(),d=read();
for(int i=;i<=n;i++)
E[i].clear();
for(int i=;i<m;i++)
{
int x=read(),y=read();
E[x].push_back(y);
E[y].push_back(x);
}
for(int p=;p<=n;p++)
{
memset(dp,,sizeof(dp));
for(int i=;i<=n;i++)
dp[][i]=1.0/n;
for(int i=;i<=d;i++)
{
for(int j=;j<=n;j++)
{
if(j==p)continue;
int N = E[j].size();
for(int k=;k<E[j].size();k++)
dp[i][E[j][k]] += dp[i-][j] * 1.0 / N;
}
}
double ans = ;
for(int i=;i<=n;i++)
{
if(i==p)continue;
ans += dp[d][i];
}
printf("%.6lf\n",ans);
}
}
}

Hdu 5001 Walk 概率dp的更多相关文章

  1. HDU - 5001 Walk(概率dp+记忆化搜索)

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

  2. HDU 3853LOOPS(简单概率DP)

    HDU 3853    LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...

  3. HDU - 1099 - Lottery - 概率dp

    http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[ ...

  4. HDU 4405 【概率dp】

    题意: 飞行棋,从0出发要求到n或者大于n的步数的期望.每一步可以投一下筛子,前进相应的步数,筛子是常见的6面筛子. 但是有些地方可以从a飞到大于a的b,并且保证每个a只能对应一个b,而且可以连续飞, ...

  5. HDU 4576 Robot(概率dp)

    题目 /*********************复制来的大致题意********************** 有N个数字,M个操作, 区间L, R. 然后问经过M个操作后落在[L, R]的概率. * ...

  6. HDU 5001 Walk

    解题思路:这是一道简单的概率dp,只要处理好相关的细节就可以了. dp[d][i]表示走d步时走到i的改概率,具体参考代码: #include<cstdio> #include<cs ...

  7. HDU 4599 Dice (概率DP+数学+快速幂)

    题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n ...

  8. [HDU 4089]Activation[概率DP]

    题意: 有n个人排队等着在官网上激活游戏.Tomato排在第m个. 对于队列中的第一个人.有以下情况: 1.激活失败,留在队列中等待下一次激活(概率为p1) 2.失去连接,出队列,然后排在队列的最后( ...

  9. hdu 3853 LOOPS 概率DP

    简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

随机推荐

  1. compass和sass很好的两篇文章

    Sass是一种"CSS预处理器",可以让CSS的开发变得简单和可维护.但是,只有搭配Compass,它才能显出真正的威力. 本文介绍Compass的用法.毫不夸张地说,学会了Com ...

  2. Springmvc构造RESTful详细讲解

    Rest介绍 /blog/1 HTTP GET => 得到id = 1的blog/blog/1 HTTP DELETE => 删除 id = 1的blog/blog/1 HTTP PUT ...

  3. Jquery Table 的基本操作

    Jquery 操作 Html Table 是很方便的,这里对表格的基本操作进行一下简单的总结. 首先建立一个通用的表格css 和一个 表格Table: table { border-collapse: ...

  4. 使用busybox制作rootfs

    Build Busybox as a static binary(no shared libs),如果选择上,则busybox将以静态形式进行编译,否则将以动态方式编译.此外,还需要对交叉编译环境进行 ...

  5. HDU 5624 KK's Reconstruction 最小生成树

    题意:这是bc round 71 div 1 的 1004 直接去看中文题意 分析: 首先,一种合法方案对应了原图的一棵生成树. 我们知道,最小生成树有一个性质是最大边最小. 因此,我们可以枚举生成树 ...

  6. jetty属性

    jetty 版本信息      Jetty7 - 此插件更名为jetty-maven-plugin,以便更符合maven2的协定.为了在Web应用做快速应用开发做准备,详见多Web应用源目录.   为 ...

  7. javaScript动态给下拉列表框添加选项

    方式一: <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></titl ...

  8. 设计模式_Observer_观察者模式

    形象例子: 想知道咱们公司最新MM情报吗?加入公司的MM情报邮件组就行了,tom负责搜集情报,他发现的新情报不用一个一个通知我们,直接发布给邮件组,我们作为订阅者(观察者)就可以及时收到情报啦.观察者 ...

  9. MFC文档、视图和框架

    文档.视图.框架 文档/视图结构是MFC提供的一种不错的设计,它将数据的处理和显示分开来,这样更便于我们对程序的维护和扩展. 文档        文档对象用于管理和维护数据,包括保存数据.取出数据以及 ...

  10. jdk源码调试功能

    JDK源码重新编译——支持eclipse调试JDK源码--转载 最近在研究jdk源码,发现debug时无法查看源码里的变量值. 因为sun提供的jdk并不能查看运行中的局部变量,需要重新编译一下rt. ...