zoukankan      html  css  js  c++  java
  • HDU 4405

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

    题意:飞行棋,可以跳,从0走到n,问期望步数

    题解:dp[i]表示从i走到n的期望,逆推,因为每次都要走一步所以递推的时候每次加1

    这类期望问题的一个大致讲解:

    http://kicd.blog.163.com/blog/static/126961911200910168335852/

    #include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    using namespace std ;
    
    double dp[100010] ;
    int h[100010] ;
    
    int main()
    {
        int n,m ;
        while(~scanf("%d%d",&n,&m))
        {
            if(!n && !m)break ;
            memset(h,0,sizeof(h)) ;
            while(m--)
            {
                int x,y ;
                scanf("%d%d",&x,&y) ;
                h[x]=y ;
            }
            memset(dp,0,sizeof(dp)) ;
            for(int i=n-1 ;i>=0 ;i--)
            {
                if(h[i])dp[i]=dp[h[i]] ;
                else
                {
                    for(int j=1 ;j<=6 ;j++)
                    {
                        dp[i]+=dp[i+j] ;
                    }
                    dp[i]=dp[i]/6+1 ;
                }
            }
            printf("%.4f
    ",dp[0]) ;
        }
        return 0 ;
    }
    View Code
  • 相关阅读:
    css圆,背景,img填满等样式
    MySQL双日志
    MySQL分层和查询数据的流程
    ZJNU 2345
    ZJNU 2342
    ZJNU 2340/2341/2343
    ZJNU 2235
    ZJNU 2226
    ZJNU 2212
    ZJNU 2208
  • 原文地址:https://www.cnblogs.com/xiaohongmao/p/3952489.html
Copyright © 2011-2022 走看看