Aeroplane chess

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4239    Accepted Submission(s):
2674

Problem Description
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.

 
Input
There 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.
 
Output
For 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
 
Source
 
Recommend
zhoujiaqi2010   |   We have carefully selected several
similar problems for you:  6032 6031 6030 6029 6028 
 
/*
本题是扔色子,其实概率也就是1/6,但是本题还有一个不同的地方,那就是可以飞行
比如从a飞到b,而不用扔色子,这些条件都会影响我们做题的方法
首先定义状态dp[i]表示处于i位置时所扔色子次数的期望,可知dp[n] = 0。
然后找找转移方程,那根据题意可知,i位置要么是可以飞行的,要么就不是
所以当i点可以飞行时,dp[i] = dp[fly[i]],其中fly[i]代表i飞行到的另一个点
否则,依据期望的定义,dp[i] = 1/6*dp[i+j] + 1,其中j = 1,2...6,代表扔色子可能的点数
最后别忘了加1,代表本次需要扔一次色子。最后,规划方向依然是从后往前,答案就是dp[0]。
*/
#include<iostream>
#include<cstdio>
#include<cstring> #define N 100005 using namespace std;
double dp[N];
int fly[N]; int main()
{
int n,m;
while(~scanf("%d%d",&n,&m) && (n||m))
{
for(int i=;i<=n;i++)
{
dp[i]=;fly[i]=-;
}
int a,b;
for(int i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
fly[a]=b;
}
for(int i=n-;i>=;i--)
{
if(fly[i]!=-) dp[i]=dp[fly[i]];
else
{
for(int j=;j<=;j++)
{
if(i+j>n) dp[i]+=1.0/*dp[n];
else dp[i]+=1.0/*dp[i+j];
}++dp[i];
}
}
printf("%.4f\n",dp[]);
}
return ;
}
 

hdu4405Aeroplane chess(概率与期望dp)的更多相关文章

  1. 【BZOJ-4008】亚瑟王 概率与期望 + DP

    4008: [HNOI2015]亚瑟王 Time Limit: 20 Sec  Memory Limit: 512 MBSec  Special JudgeSubmit: 832  Solved: 5 ...

  2. 概率和期望dp

    概率和期望dp 概率和期望好神啊,完全不会. 网上说概率要顺着推,期望要逆着推,然而我目前做的概率期望题正好都与此相反2333   概率: 关于概率:他非常健康 初中概率题非常恐怖.现在来思考一道题: ...

  3. 【CodeForces】913 F. Strongly Connected Tournament 概率和期望DP

    [题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之 ...

  4. 概率与期望dp相关

    概率与期望dp 概率 某个事件A发生的可能性的大小,称之为事件A的概率,记作P(A). 假设某事的所有可能结果有n种,每种结果都是等概率,事件A涵盖其中的m种,那么P(A)=m/n. 例如投掷一枚骰子 ...

  5. 【算法学习笔记】概率与期望DP

    本文学习自 Sengxian 学长的博客 之前也在CF上写了一些概率DP的题并做过总结 建议阅读完本文再去接着阅读这篇文章:Here 前言 单纯只用到概率的题并不是很多,从现有的 OI/ACM 比赛中 ...

  6. hdu4405Aeroplane chess 概率dp水题

    //从0到n有n+1个格子 //对于格子i,掷一次骰子的数为x.那么能够从位置i到位置i+x //格子之间有连线,假设格子a和b有连线,那么从a到b不用掷骰子 //求从0到n的骰子掷的次数的期望 // ...

  7. HDU4405 Aeroplane chess 飞行棋 期望dp 简单

    http://acm.hdu.edu.cn/showproblem.php?pid=4405   题意:问从起点到终点需要步数的期望,1/6的概率走1.2.3.4.5.6步.有的点a有路可以直接到b, ...

  8. 概率及期望DP小结

    资源分享 26 个比较概率大小的问题 数论小白都能看懂的数学期望讲解 概念 \(PS\):不需要知道太多概念,能拿来用就行了. 定义 样本(\(\omega\)):一次随机试验产生的一个结果. 样本空 ...

  9. 【BZOJ-3450】Tyvj1952Easy 概率与期望DP

    3450: Tyvj1952 Easy Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 468  Solved: 353[Submit][Status] ...

随机推荐

  1. (转)Java任务调度框架Quartz入门教程指南(三)任务调度框架Quartz实例详解深入理解Scheduler,Job,Trigger,JobDetail

    http://blog.csdn.net/zixiao217/article/details/53053598 首先给一个简明扼要的理解: Scheduler 调度程序-任务执行计划表,只有安排进执行 ...

  2. win10系统安装postgresql后无法连接

    win10系统安装postgresql后在系统服务列表中找不到,连接不上数据库. 可以尝试关闭系统防火墙后重启电脑或者重装程序.

  3. C解析config

    #cat bb.c #include <stdio.h> #include <stdlib.h> #include <string.h> #include < ...

  4. codevs2833 奇怪的梦境

    2833 奇怪的梦境  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解       题目描述 Description Aiden陷入了一个奇怪的梦境:他被困 ...

  5. 推荐系统相关比赛-kaggle

    from: 七月在线 电商推荐与销量预测相关案例 一.预测用户对哪个事件感兴趣(感兴趣不一定去参加) 用户历史参加事件.社交信息.浏览信息(app).要预测的事件 recall:召回率 准确率: 协同 ...

  6. [LUOGU] 4933 大师

    \(Orz\) \(ljt12138!\) 设状态\(f[i][j]\)表示以\(i\)为结尾,公差为\(j\)的长度大于\(1\)的数列有几个. 然后转移方程就很好想了. \(k=H[i]-H[j] ...

  7. Scrapy下载器中间件用法示例

    1.爬虫文件httpbin.py # -*- coding: utf-8 -*- import scrapy class HttpbinSpider(scrapy.Spider): name = 'h ...

  8. Linux下的find命令

    Linux下find命令在目录结构中搜索文件,并执行指定的操作.Linux下find命令提供了相当多的查找条件,功能很强大.即使系统中含有网络文件系统,find命令在该文件系统中同样有效.在运行一个非 ...

  9. 腾讯云,搭建nginx静态网站服务器

    搭建Http静态服务器环境 任务时间:15min ~ 30min 搭建静态网站,首先需要部署环境.下面的步骤,将告诉大家如何在服务器上通过 Nginx 部署 HTTP 静态服务. 安装 Nginx 在 ...

  10. 在Docker上构建mysql容器

    1.查看docker上的镜像是否有 mysql,如果没有下载则列表中没有  [root@holly holly]# docker images; 如果没有只会看到如下结构 REPOSITORY  TA ...