DP in the HDU 5001 probability DP Diagram

Source: Internet
Author: User

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 5001

At that time, when I saw the figure, I fell down and did not dare to write it, nor did I return the DP equation.

I feel that the question of the semi-finals is a bit difficult to think of. The second is that coding is a bit difficult.

This question:

I keep thinking that 1-the probability of reaching I is the probability of not reaching I, and then the three-dimensional equation barabara, confused myself.

Correct practice:
DP [k] [J] After J steps reach K points and the probability of not passing through I points is set so that the probability of not reaching I points can be obtained. Segma (DP [v] [J-1]/g [v]. size () V is the adjacent node with K, if the J-1 step reaches step v j there is 1/g [v]. the probability of size () reaches K.

// # Pragma comment (linker, "/Stack: 102400000,102400000 ") # include <cstdio> # include <cstring> # include <algorithm> # include <string> # include <iostream> # include <iomanip> # include <cmath> # include <map> # include <set> # include <queue> using namespace STD; # define ls (RT) rt * 2 # define RS (RT) rt * 2 + 1 # define ll long # define ull unsigned long # define rep (I, S, e) for (INT I = s; I <E; I ++) # define repe (I, S, e) for (int I = s; I <= E; I ++) # define Cl (a, B) memset (a, B, sizeof (A) # define in (s) freopen (S, "r", stdin) # define out (s) freopen (S, "W", stdout) const ll ll_inf = (ull) (-1)> 1; const double EPS = 1e-8; const double Pi = ACOs (-1.0); const int INF = 100000000; const int maxn = 60; const int max = 10000 + 100; double ans [maxn]; double DP [maxn] [Max]; vector <int> G [Max]; int n, m, D; void solve () {for (INT I = 1; I <= N; I ++) {Cl (DP, 0); For (int J = 1; j <= D; j ++) {If (j = 1) {for (int K = 1; k <= N; k ++) if (K! = I) DP [k] [J] = 1.0/N; // select a random vertex in the first step to reach any vertex, so the probability is 1.0/n} else {for (int K = 1; k <= N; k ++) if (K! = I) {for (INT T = 0; t <G [K]. size (); t ++) {int v = G [k] [T]; If (V! = I) DP [k] [J] + = DP [v] [J-1]/g [v]. size () ;}}} double out = 0.0; For (Int J = 1; j <= N; j ++) if (J! = I) out + = DP [J] [d]; printf ("%. 10lf \ n ", out) ;}} int main () {// In (" hdu5001.txt "); int ncase; scanf (" % d ", & ncase ); while (ncase --) {for (INT I = 0; I <= N; I ++) g [I]. clear (); // For (INT I = 0; I <= N; I ++) ans [I] = 0.0; scanf ("% d ", & N, & M, & D); D ++; // int U, V; For (INT I = 0; I <m; I ++) {scanf ("% d", & U, & V); G [u]. push_back (V); G [v]. push_back (U);} solve ();} return 0 ;}


DP in the HDU 5001 probability DP Diagram

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.