Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3,4,5,6). When Hzz is at grid i and the dice number is x, he will moves to grid i+x. Hzz finishes the game when i+x is equal to or greater than N.

There are also M flight lines on the chess map. The i-th flight line can help Hzz fly from grid Xi to Yi (0<Xi<Yi<=N) without throwing the dice. If there is another flight line from Yi, Hzz can take the flight line continuously. It is granted that there is no two or more flight lines start from the same grid.

Please help Hzz calculate the expected dice throwing times to finish the game.

InputThere are multiple test cases. 
Each test case contains several lines. 
The first line contains two integers N(1≤N≤100000) and M(0≤M≤1000). 
Then M lines follow, each line contains two integers Xi,Yi(1≤Xi<Yi≤N).   
The input end with N=0, M=0. 
OutputFor each test case in the input, you should output a line indicating the expected dice throwing times. Output should be rounded to 4 digits after decimal point.

Sample input

2 0
8 3
2 4
4 5
7 8
0 0

Sample Output

1.1667
2.3441 题意:一种飞行棋,起点为 0 ,掷一次骰子,可以走有 1-6 步,飞到 >= n 就赢了,有 m 个可以直接飞的点,n,m 都为 0 输入结束 ,问需要掷骰子的次数期望 题解:简单概率dp
逆推即可,还有就是,飞的起点和终点的期望相同
 #include <iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std; #define MAXN 100010 int far[MAXN];
double dp[MAXN]; int main()
{
int n,m;
while (scanf("%d%d",&n,&m)&&(n||m))
{
memset(far,-,sizeof(far));
while (m--)
{
int x,y;
scanf("%d%d",&x,&y);
far[x]=y;
}
memset(dp,,sizeof(dp)); for (int i=n;i>=;i--)
{
if (far[i]==-)
{
for (int j=;j<=;j++)
dp[i]+=dp[i+j]/6.0;
dp[i]+=1.0;
if (i==n) dp[i]=0.0;
}
else dp[i]=dp[far[i]];
}
printf("%.4lf\n",dp[]);
}
return ;
}
												

Aeroplane chess(简单概率dp)的更多相关文章

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

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

  2. hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  3. hdu 4405 Aeroplane chess(概率+dp)

    Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...

  4. HDU 4405 Aeroplane chess (概率DP求期望)

    题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...

  5. HDU-4405 Aeroplane chess(概率DP求期望)

    题目大意:一个跳棋游戏,每置一次骰子前进相应的步数.但是有的点可以不用置骰子直接前进,求置骰子次数的平均值. 题目分析:状态很容易定义:dp(i)表示在第 i 个点出发需要置骰子的次数平均值.则状态转 ...

  6. hdu 4405 Aeroplane chess(简单概率dp 求期望)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. HDU 3853LOOPS(简单概率DP)

    HDU 3853    LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...

  8. 简单概率dp(期望)-zoj-3640-Help Me Escape

    题目链接: http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4808 题目大意: 有n条路,选每条路的概率相等,初始能力值为f,每 ...

  9. hdu4405--Aeroplane chess(概率dp第七弹:飞行棋游戏--2012年网络赛)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

随机推荐

  1. python测试与调试提示

    测试与调试提示 2.1 在交互模式输入一个python语句就会执行一个.在调试程序时,这种模式尤其有用. 2.2 在一个文件调用python解释器后,解释器会在文件中的最后一个语句执行之后推出.然而, ...

  2. HTML5游戏实战(1):50行代码实现正面跑酷游戏

    前段时间看到一个"熊来了"的HTML5跑酷游戏,它是一个典型的正面2D跑酷游戏,这里借用它来介绍一下用Gamebuilder+CanTK开发正面跑酷游戏的基本方法. CanTK(C ...

  3. Elasticsearch 之 query与filter区别

    转载: http://xiaorui.cc/category/elasticsearch/ http://blog.csdn.net/asia_kobe/article/details/5056301 ...

  4. java中数组的复制

    数组复制使我们在编程过程中经常要使用到的,在java中数组复制我们大概能够分为两种,一种是引用复制,还有一种就是深度复制(复制后两个数组互不相干). 以下我们就通过測试的方法来具体看看什么是引用复制和 ...

  5. angular 中表单验证的探索

    需求 之前有一段时间做一个搜索查询 但是有很多限制条件,如果校验不成功需要给用户提示错误,当然项目用的是组件库的校验 我能否自己写一个? 其实 我是不会的!!! 探索 angular 的校验功能很强大 ...

  6. 改进xutils下载管理器,使其,在随意地方进行进度更新,以及其它状态监听操作

    1.前面在做下载进度监听.尝试过,通过加入 弱引用的View进度条,到相应的集合. 等到要进行更新进度的时候.通过Key 获取相应的VIew来进行更新 进度条.效果是达到了,可是我们怎样来监听其它的状 ...

  7. pugixml 的常见读写操作

    pugixml github地址 : https://github.com/zeux/pugixml pugixml 可以在github上直接下载到源码,包括两个头文件(pugixml.hpp  pu ...

  8. C# 反编译工具

    justdecompile http://down.51cto.com/data/2067031 ILSpy http://www.fishlee.net/soft/ilspy_chs/

  9. Android蓝牙

    代码地址如下:http://www.demodashi.com/demo/12772.html 前言:最近,新换了一家公司,公司的软件需要通过蓝牙与硬件进行通讯,于是趁此机会将Android蓝牙详细的 ...

  10. hdu 2871 Memory Control(线段树)

    题目链接:hdu 2871 Memory Control 题目大意:模拟一个内存分配机制. Reset:重置,释放全部空间 New x:申请内存为x的空间,输出左地址 Free x:释放地址x所在的内 ...