HDU 4405 Aeroplane Chess probability DP Difficulty: 0

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=4405

Obviously, there is no need to consider the dice when the plane, must be better by plane

Set E[i] for the number of steps that are required to walk at the point of I, J is one of the possible points to be cast, if deduced from I to i-j, we are not able to determine the transfer direction of I, because there may be two i-j with a plane whose destination is I, so we choose to derive the desired from I to i+j

If you set g[i] to the number of steps you have already traversed as a fraction of I, be sure that g[i+j] needs to know P (I|I+J), which is the probability of moving from I to the i+j, which is more troublesome

From test instructions, set Match[i] as the destination of the aircraft I, when Match[i] exists, e[i]=e[match[i]], otherwise e[i]=sigma ((e[i+j]+1) * (1/6)), J in range (6)

#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn=1e5+5; Double E[maxn];int match[maxn];int n,m;void init () {    memset (e,0,sizeof (e));    memset (match,0,sizeof (Match));    for (int i=0;i<m;i++) {        int f,t;        scanf ("%d%d", &f,&t);        match[f]=t;}    } int lt (int a) {return min (a,n);} void Calc () {for    (int i=n-1; i>=0; i--)    {        if (match[i]!=0) e[i]=e[lt (Match[i])];        else        {for            (int j=1; j<=6; j + +)            {                e[i]+= (e[lt (i+j)]+1)/6;            }    }}} int main () {    for (int ti=1; scanf ("%d%d", &n,&m) ==2&& (n| | m); ti++)    {        init ();        Calc ();        printf ("%.4f\n", E[0]);    }    return 0;}

HDU 4405 Aeroplane Chess probability DP Difficulty: 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.