Portal
Walk
Time limit:30000/15000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 996 Accepted Submission (s): 634
Special Judge
Problem Description
I used to think I could is 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'll travel to a adjacent node with the same probability in the next step. I'll pick up the start node randomly (each node in the graph have 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'll make me unhappy. So I wonder to each node, what's the probability that my path doesn ' t contain it.
Input
The first line contains an integer T, denoting the number of the 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 an d The number of steps respectively. Then M. lines follows, each containing, integers a and B, denoting there are 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 is 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 would be the 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
ACM/ICPC Asia Regional Anshan Online
Main topic:
First give the n points, M edge, and then given a walk step number step, a person at the point of the graph (with side) walking, starting from each point to walk the same probability, from each point to its adjacent points of the probability of each point is equal. You ask for not to pass I (1<= i <=n) The probability of a point
Problem Solving Ideas:
At that time I looked at the topic, I glanced at a few eyes, I see this is not a picture of the problem, Ka to the teammates, and then the teammate is not AH/Khan, is a question about probability, I said then I look. Really is a probability of the topic, we can set DP[I][J] is to walk I step to the probability of reaching the J point, in fact, DP is mainly to write a state transfer equation so the probability DP of course Also
We can think so dp[i][j] how come, certainly is to walk i-1 step to, then go to i-1 step of time so sure to go is with J Point adjacent to that point (that is, there is edge point) so walk I step to J point probability is
The probability is the current dp[i-1][vec[k][l]]/vec[k].size (), where the vector array is the current point with several edges and is saved
DP [I][J]+=DP [I?1][veC[k][L]]/veC[k].sIz e()
We're asking for less than the probability of the I point, then we throw the point, then the probability of less than the I point is
DP[STEP][J] (j!=i).
My Code:
#include <iostream>#include <cstring>#include <cstdio>#include <vector>using namespace STD;Const intMaxn_n = -;Const intMaxn_step =10005; vector <int>Vec[maxn_n];DoubleDp[maxn_step][maxn_n];intMain () {intT, M, N, step;Cin>>T; while(t--) {Cin>>n>>m>>step; for(intI=0; i<maxn_n; i++) vec[i].clear ();intU, v; for(intI=0; i<m; i++) {Cin>>u>>v; Vec[u].push_back (v); Vec[v].push_back (U); } for(intI=1; i<=n; i++) dp[0][i] =1.0/n; for(intI=1; i<=n; i++) { for(intj=1; j<=step; J + +) { for(intk=1; k<=n; k++) {if(i = = k)Continue; DP[J][K] =0; for(intL=0; L<vec[k].size (); l++) {if(Vec[k][l]! = i) dp[j][k] + = dp[j-1][vec[k][l]]* (1.0/vec[k].size ()); } } }DoubleAns =0; for(intj=1; j<=n; J + +) {if(J! = i) ans + = dp[step][j]; }printf("%.6lf\n", ans); } }return 0;}
HDU 5001 Walk (probabilistic DP)