HDU 4405 probability DP 2012 Jinhua Asia Network Competition-although water, it is the first probability DP independently made by myself

Source: Internet
Author: User

Question: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 4405


E [I]: expected number of steps to be taken at the current position I

Inspired by Liu rujia's suffix link Writing Method of the AC automatic machine, X [I] can reach the longest distance when "flight line" is continuous in reverse order,

        rep(i,0,m)        {            scanf("%d%d",&xx,&yy);            x[xx]=yy;        }        for(int i=n;i>=0;i--)            if(x[i]!=-1 && x[x[i]] != -1)                x[i]=x[x[i]];
I made a two-way mistake when I wrote it, and I thought I was wrong with the equation. For more information, see comments.

# Include <cstdio> # include <iostream> # include <cstring> using namespace STD; # 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 reped (I, S, E) for (INT I = s; I> = E; I --) # define arclr (AA, v) memset (AA, V, sizeof (AA )) const Double P = 1.0/6; const int maxn = 100000 + 30; Double E [maxn], P2; int X [maxn]; int main () {// freopen ("hdu1_5.txt", "r", stdin); int XX, YY, n, m; while (~ Scanf ("% d", & N, & M) & N + M) {// P2 = m * 1.0/N; arclr (x, 0xff ); rep (I, 0, m) {scanf ("% d", & XX, & YY); X [XX] = YY ;}for (INT I = N; i> = 0; I --) if (X [I]! =-1 & X [x [I]! =-1) x [I] = x [x [I]; arclr (E, 0); reped (I, n-1, 0) {If (X [I] =-1) {reped (J, 6, 1) E [I] + = E [I + J]; E [I] = E [I]/6.0 + 1; continue;} If (X [I]! =-1 & X [x [I]! =-1) {e [x [I] = E [x [x [I]; X [I] = x [x [I]; // write it as X [I] = x [I + X [I]. The second is forced.} e [I] = E [x [I];} printf ("%. 4lf \ n ", E [0]);} return 0 ;}


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.