HDU 4405 aeroplane chess (expected)

Source: Internet
Author: User

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


There are n + 1 points, 0 ~ N. A person is standing at X now. If Flight lines exists at X, he can fly to the corresponding point without rolling the dice. Otherwise, he will move forward to the number on the dice. Asked him the average number of times he needed to throw a dice from.


For the same question type, DP [N] is known to be 0, and then the inverse is performed based on the probability that the current point can reach the next point. DP [0] is the answer.


#include <stdio.h>#include <iostream>#include <map>#include <set>#include <list>#include <stack>#include <vector>#include <math.h>#include <string.h>#include <queue>#include <string>#include <stdlib.h>#include <algorithm>//#define LL __int64#define LL long long#define eps 1e-9#define PI acos(-1.0)using namespace std;const int INF = 0x3f3f3f3f;const int maxn = 4010;double dp[100010];int hash[100010];int main(){    int n,m,u,v;    while(~scanf("%d %d",&n,&m))    {        if(n == 0 && m == 0)            break;        memset(dp,0,sizeof(dp));        memset(hash,-1,sizeof(hash));        while(m--)        {            scanf("%d %d",&u,&v);            hash[u] = v;        }        for(int i = n; i >= 0; i--)        {            if(i == n) continue;if(hash[i] == -1)            {            for(int j = i+1; j <= i+6; j++)dp[i] += dp[j];dp[i] /= 6;dp[i] += 1;            }elsedp[i] = dp[hash[i]];        }        printf("%.4lf\n",dp[0]);    }    return 0;}


HDU 4405 aeroplane chess (expected)

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.