Walk

Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 266    Accepted Submission(s): 183 Special Judge

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
 
Recommend
hujie   |   We have carefully selected several similar problems for you:  5017 5016 5015 5014 5013 
 
 
设dp[j][d]表示不能经过i点走了d步到达j点的概率。那么dp[j][d] = ∑ dp[k][d-1]/edge[k].size()。那么不经过i点的概率为∑dp[j][D]。(转自:http://blog.csdn.net/u013081425/article/details/39254337) (我的代码是dp[d][j])
每次都去掉一个点求出到达 其他点的概率就是不能到达这个点的概率。(转自:http://blog.csdn.net/xu12110501127/article/details/39254403)
 #include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<string> #define N 55
#define M 15
#define mod 1000000007
#define p 10000007
#define mod2 100000000
#define ll long long
#define LL long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int T;
int n,m,d;
vector<int>bian[N];
int cnt[N];
double dp[][N];
double re; void ini()
{
int i;
int x,y;
memset(cnt,,sizeof(cnt));
scanf("%d%d%d",&n,&m,&d);
for(i=;i<=n;i++){
bian[i].clear();
}
while(m--){
scanf("%d%d",&x,&y);
bian[x].push_back(y);
bian[y].push_back(x);
}
for(i=;i<=n;i++){
cnt[i]=bian[i].size();
}
} void solve()
{
int q,o,i;
for(q=;q<=n;q++)
{
re=;
memset(dp,,sizeof(dp));
for(i=;i<=n;i++){
if(i==q) continue;
dp[][i]=1.0/n;
} for(o=;o<=d;o++){
for(i=;i<=n;i++){
if(i==q) continue;
for(vector<int>::iterator it=bian[i].begin();it!=bian[i].end();it++){
dp[o][i]+=dp[o-][*it]/cnt[*it];
}
}
} for(i=;i<=n;i++){
if(i==p) continue;
re+=dp[d][i];
}
printf("%.10f\n",re);
}
} void out()
{
//printf("%I64d\n",ans);
} int main()
{
//freopen("data.in","r",stdin);
scanf("%d",&T);
//for(int cnt=1;cnt<=T;cnt++)
while(T--)
//while(scanf("%I64d%I64d",&n,&m)!=EOF)
{
ini();
solve();
// out();
} return ;
}

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 4089 Activation(概率DP)(转)

    11年北京现场赛的题目.概率DP. 公式化简起来比较困难....而且就算结果做出来了,没有考虑特殊情况照样会WA到死的.... 去参加区域赛一定要考虑到各种情况.   像概率dp,公式推出来就很容易写 ...

  3. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  4. HDU 5001 Walk

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

  5. Hdu 5001 Walk 概率dp

    Walk Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5001 Desc ...

  6. HDU 4576 Robot (概率DP)

    暴力DP求解太卡时间了...........写挫一点就跪了 //hdu robot #include <cstdio> #include <iostream> #include ...

  7. HDU 2955 Robberies 背包概率DP

    A - Robberies Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submi ...

  8. HDU 3366 Passage (概率DP)

    Passage Problem Description Bill is a millionaire. But unfortunately he was trapped in a castle. The ...

  9. 2016ACM/ICPC亚洲区沈阳站H - Guessing the Dice Roll HDU - 5955 ac自动机+概率dp+高斯消元

    http://acm.hdu.edu.cn/showproblem.php?pid=5955 题意:给你长度为l的n组数,每个数1-6,每次扔色子,问你每个串第一次被匹配的概率是多少 题解:先建成ac ...

随机推荐

  1. UVA1663 Purifying Machine (匈牙利算法,二分图最大匹配)

    模版集合个数减少是因为匹配串集合中没被匹配过的一对串匹配了.所以就是找一个二分图最大匹配. 因为集合X和Y是不好分开的,但是可以直接跑,两个集合都会跑一遍,所以一个匹配会被算两次,返回的时候除以2就行 ...

  2. 标注偏置问题(Label Bias Problem)和HMM、MEMM、CRF模型比较<转>

    转自http://blog.csdn.net/lskyne/article/details/8669301 路径1-1-1-1的概率:0.4*0.45*0.5=0.09 路径2-2-2-2的概率:0. ...

  3. Web中打印的各种方案参考

    http://blog.csdn.net/chinahuyong/article/details/42527491

  4. 升级nodejs 与短小的n模块

    要用指令升级nodejs到新版本要先安装n模块 window用不了n模块  可以用 nvm-windows : https://github.com/coreybutler/nvm-windows n ...

  5. javascript获取属性的两种方法及区别

    javascript获取属性有两种方式,点或者中括号: var obj={} obj.x=1 console.log(obj.x)//1 第一种方式,x是字面量 try{ console.log(ob ...

  6. 【数位dp】bzoj1799: [Ahoi2009]self 同类分布

    各种奇怪姿势的数位dp Description 给出a,b,求出[a,b]中各位数字之和能整除原数的数的个数. Sample Input 10 19 Sample Output 3 HINT [约束条 ...

  7. [POJ] 1135 Domino Effect

    Domino Effect Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 12147 Accepted: 3046 Descri ...

  8. CSS3-媒体类型

    一.媒体类型(Media Type) 1.link方法引入 <link rel="stylesheet" type="text/css" href=&qu ...

  9. python--MySQL多表查询

    一 介绍 我们在写项目的时候一般都会建一个数据库,数据库里面会存很多的表,不可能把所有的数据都放在一张表里,因为分表来存数据节省空间,数据的组织结构更清晰,解耦和程度更高,但是这些表本质上还不是一个整 ...

  10. Day13有参装饰器,三元表达式,匿名函数

    多个装饰器: 加载顺序:由下而上 执行顺序:由上而下 有参装饰器: 闭包,给函数传参的一种方法 当装饰器内需要参数时,可以采用闭包形式给其传参,第三层函数接收完参数时,就变为无参装饰器 三元表达式: ...