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[] ;
int h[] ; int main()
{
int n,m ;
while(~scanf("%d%d",&n,&m))
{
if(!n && !m)break ;
memset(h,,sizeof(h)) ;
while(m--)
{
int x,y ;
scanf("%d%d",&x,&y) ;
h[x]=y ;
}
memset(dp,,sizeof(dp)) ;
for(int i=n- ;i>= ;i--)
{
if(h[i])dp[i]=dp[h[i]] ;
else
{
for(int j= ;j<= ;j++)
{
dp[i]+=dp[i+j] ;
}
dp[i]=dp[i]/+ ;
}
}
printf("%.4f\n",dp[]) ;
}
return ;
}

HDU 4405的更多相关文章

  1. 概率dp HDU 4405

    Aeroplane chess Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  2. HDU 4405 (概率DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 题目大意:飞行棋.如果格子不是飞行点,扔骰子前进.否则直接飞到目标点.每个格子是唯一的飞行起点 ...

  3. HDU 4405:Aeroplane chess(概率DP入门)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description   Hzz loves ...

  4. HDU 4405 Aeroplane chess 概率DP 难度:0

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...

  5. HDU 4405 Aeroplane chess(期望)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:从0走到n,每次走之前掷一次筛子,掷出几点就向前走几点,走到大于等于n的地方就停止.但是, ...

  6. HDU 4405 Aeroplane chess 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...

  7. HDU 4405 Aeroplane chess:期望dp

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意: 你在下简化版飞行棋... 棋盘为一个线段,长度为n. 上面有m对传送门,可以直接将你从a ...

  8. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  9. HDU 4405 期望DP

    期望DP算是第一题吧...虽然巨水但把思路理理清楚总是好的.. 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落到a点时直接飞向b点.求走到n ...

随机推荐

  1. GPOR

    [tengzhenzhen15@lu01 gpor]$ for ((i=0; i<=19; i++)) do ./gpor -S 0.4 X4058_300_gpor/mytask_train. ...

  2. fill_parent和wrap_content的区别

    在Android布局文件中定义视图垂直或水平大小: android:layout_width和android_layout_height的属性有fill_parent.wrap_content和mat ...

  3. JDE报表开发笔记(R5537011 收货校验统计表)

    业务场景:根据批次收货,收货后对该批次产品进行检验,记录检验结果生成统计表. 涉及表:主表F37011,业务从表F43121/F4101/F4108 ------------------------- ...

  4. Visual Studio 2012中的为创建类时的添加注释模板

    我们往往需要给类添加注释,我们可以把注释块复制出来,放到文件中,然后在需要的时候,复制.粘贴.这样的重复劳动增加了程序员的体力劳动,而VS中给我们提供了项模版,我们只需要在其中修改一点点模版就能达到这 ...

  5. centos 卸载软件·

    centos下完全卸载php 1显示相关软件的列表 rpm -qa  | grep i(可以不加) php 2 卸载即可 rpm -e 软件名 --nodeps centos下完全卸载mysql 1显 ...

  6. 基础的 Linux 网络命令,你值得拥有

    导读 有抱负的 Linux 系统管理员和 Linux 狂热者必须知道的.最重要的.而且基础的 Linux 网络命令合集.在 It's FOSS 我们并非每天都谈论 Linux 的"命令行方面 ...

  7. ASP.NET MVC4 部分视图

    ASP.NET MVC4 部分视图 2014-10-24 16:48 by 易code, 2662 阅读, 1 评论, 收藏, 编辑 [部分视图] ASP.NET MVC 里的部分视图,相当于 Web ...

  8. POJ 2159 Ancient Cipher 难度:0

    题目链接:http://poj.org/problem?id=2159 #include <cstring> #include <cstdio> #include <cc ...

  9. POJ 1422 二分图(最小路径覆盖)

    Air Raid Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 7278   Accepted: 4318 Descript ...

  10. C#根据当前日期获取星期和阴历日期

    private string GetWeek(int dayOfWeek) { string returnWeek = ""; switch (dayOfWeek) { case ...