Question: N points (1 ~ N), m edges walk K times, two-way edges, each random walk a path, the starting point is also random, and the probability of not going to each point is how much.
Ideas:
Probability DP [I] [J] [k] the probability that step I will walk to J less than K.
Then, state transfer is the point where J can reach. It transfers the upper probability of all DP [I] [J] [k] values.
Code:
# Include "cstdlib" # include "cstdio" # include "cstring" # include "cmath" # include "stack" # include "algorithm" # include "iostream" # include "vector" using namespace STD; # define n 300000 double DP [3] [55] [55]; // use the scrolling array int main () {int t; CIN> T due to memory problems; while (t --) {int n, m, D; scanf ("% d", & N, & M, & D ); vector <int> edge [55]; while (M --) {int A, B; scanf ("% d", & A, & B ); edge [A]. push_back (B); edge [B]. push_back (a);} memset (DP, 0, sizeof (DP); int I, J, K, L; for (I = 1; I <= N; I ++) {for (j = 1; j <= N; j ++) {If (J! = I) DP [0] [I] [J] + = 1.0/N; // initialization, it is because the starting point is in I, so the probability of not going to J is all 1} for (I = 1; I <= D; I ++) {memset (DP [I % 2], 0, sizeof (DP [I % 2]); For (j = 1; j <= N; j ++) {for (k = 0; k <(INT) edge [J]. size (); k ++) {for (L = 1; L <= N; l ++) {If (J! = L & J! = Edge [J] [k]) DP [I % 2] [edge [J] [k] [l] + = DP [1-I % 2] [J] [l] * 1.0/edge [J]. size () ;}}} double ans [55]; memset (ANS, 0, sizeof (ANS); for (I = 1; I <= N; I ++) {for (j = 1; j <= N; j ++) if (I! = J) ans [I] + = DP [d % 2] [J] [I] ;}for (I = 1; I <= N; I ++) printf ("%. 10f \ n ", ANS [I]);} return 0 ;}
[Probability DP] HDU 5001 walk