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
  • 相关阅读:
    HDU 5650 异或
    HDU 5646
    HDU 5645
    P2075 [NOIP2012T5]借教室 区间更新+二分查找
    HDU 5641
    读写分离
    linux执行cmd之一
    html2image
    挂载引起的权限问题
    如何防止sql注入
  • 原文地址:https://www.cnblogs.com/xiaohongmao/p/3952489.html
Copyright © 2011-2022 走看看