Channel: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4035
There are n rooms connected by N-1 tunnels. In fact, a tree is formed. Starting from node 1, there are three possibilities for each node I:
1. Killed, return to node 1 (probability is Ki)
2. Find the exit and exit the maze (probability is EI)
3. There are m edges connected to the vertex and a Random Edge is taken.
The expected value of the number of edges to walk out of the maze.
Ideas:
Set E [I] to represent the expected number of edges to walk out of the maze at node I. E [1] is the request. Leaf node: E [I] = Ki * E [1] + EI * 0 + (1-ei EI) * (E [Father [I] + 1 ); = Ki * E [1] + (1-0000ei) * E [Father [I] + (1-0000ei); Non-leaf node: (m is the number of edges connected to the node) E [I] = Ki * E [1] + EI * 0 + (1-ei EI) /M * (E [Father [I] + 1 + Σ (E [child [I] + 1); = Ki * E [1] + (1-127ei) /M * E [Father [I] + (1-0000ei)/m * Σ (E [child [I]) + (1-0000ei); set each node: E [I] = ai * E [1] + bi * E [Father [I] + ci; for non-leaf node I, set J to the child node of I, then Σ (E [child [I]) = Σ E [J] = Σ (AJ * E [1] + Bj * E [Father [J] + cj) = Σ (AJ * E [1] + Bj * E [I] + cj) Bring the formula above (1-(1-ei EI)/m * Σ BJ) * E [I] = (KI + (1-0000ei)/m * Σ AJ) * E [1] + (1-0000ei) /M * E [Father [I] + (1-0000ei) + (1-0000ei)/m * Σ CJ; thus, AI = (KI + (1-0000ei)/m * Σ AJ) can be obtained) /(1-(1-0000ei)/m * Σ BJ); Bi = (1-0000ei)/M/(1-(1-0000ei)/m * Σ BJ ); ci = (1-digit EI) + (1-digit EI)/m * Sigma CJ)/(1-(1-digit EI)/m * Sigma BJ); for leaf node AI = Ki; bi = 1-ki-EI; CI = 1-ki-EI; Starting from the leaf node until A1, B1, and c1 are calculated; E [1] = A1 * E [1] + B1 * 0 + C1; so E [1] = C1/(1-A1 ); if A1 approaches 1, there is no solution... (transferred from kuangbin)
Code:
Tag: Classic expectation DP
[Probability and expectation] HDU 4035