hdu 4405 Aeroplane chess(概率+dp)
Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled from to N. Hzz starts at grid . 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 ,,,,,). 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 (<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.
There are multiple test cases.
Each test case contains several lines.
The first line contains two integers N(≤N≤) and M(≤M≤).
Then M lines follow, each line contains two integers Xi,Yi(≤Xi<Yi≤N).
The input end with N=, M=.
For each test case in the input, you should output a line indicating the expected dice throwing times. Output should be rounded to digits after decimal point.
1.1667
2.3441
这道题适合从后面开始dp。将能跳的格子标志了,然后从n-1开始dp。具体看代码吧,不知道怎么说了。。。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100006
int n,m;
double dp[N];
int vis[N];
int main()
{
while(scanf("%d%d",&n,&m)== && n+m){
memset(vis,-,sizeof(vis));
memset(dp,,sizeof(dp));
for(int i=;i<m;i++){
int x,y;
scanf("%d%d",&x,&y);
vis[x]=y;
}
for(int i=n-;i>=;i--){
if(vis[i]!=-){
dp[i]=dp[vis[i]];
}else{
for(int j=;j<=;j++){
dp[i]+=dp[i+j]/;
}
dp[i]+=1.0;
}
}
printf("%.4lf\n",dp[]);
}
return ;
}
hdu 4405 Aeroplane chess(概率+dp)的更多相关文章
- [ACM] hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- HDU 4405 Aeroplane chess 概率DP 难度:0
http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...
- HDU 4405 Aeroplane chess(概率dp,数学期望)
题目 http://kicd.blog.163.com/blog/static/126961911200910168335852/ 根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什 ...
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4405 Aeroplane chess(简单概率dp 求期望)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- 【刷题】HDU 4405 Aeroplane chess
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...
- HDU 4405 Aeroplane chess (概率DP求期望)
题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...
随机推荐
- html5 750 REM JS换算方法
在安卓手机低版本浏览器,如果进页面快速执行的话会出现计算宽度不正确的情况,解决方法是放在onload方法里面执行,但这种解决方式在一些高版本浏览器中会出现页面闪动,所以使用判断浏览器版本的方式来解决, ...
- python3-day5(模块)
1.获取路径import os,sys #获取全部路径 print(os.path.abspath(__file__)) #获取目录 print(os.path.dirname(os.path.abs ...
- python linecache标准库基础学习
#python标准库基础之:linecacge:高效读取文本文件#说明与作用"""可以从文件或者导入python模块获取文件,维护一个结果缓存,从而可以更高效地从相同文件 ...
- 并发情况下synchronized死锁
存在缺陷的代码: public class DataPropertyIdAndNameRepositoryImpl{ /** 发布标志 */ private volatile boolean publ ...
- stat(),lstat(),fstat() 获取文件/目录的相关信息
stat 的使用 Linux有个命令,ls -l,效果如下: 这个命令能显示文件的类型.操作权限.硬链接数量.属主.所属组.大小.修改时间.文件名.它是怎么获得这些信息的呢,请看下面的讲解. stat ...
- [转载]aptitude与apt-get的区别和联系
转自 http://www.cnblogs.com/yuxc/archive/2012/08/02/2620003.html 命令 下面将要介绍的所有命令都需要sudo!使用时请将“packagena ...
- asp.net服务器向客户端弹出对话框,但不使页面边白板
1: using System; 2: using System.Collections.Generic; 3: using System.Linq; 4: using System.Web; 5: ...
- java.sql.SQLException: ORA-00911: 无效字符 解决方案
在使用java执行sql时,抛出的这样一个Oracle异常,最后发现是sql语句末尾有一个分号导致,例如:sql="select * from tl_demo;" .删除" ...
- “文件XXX正由另一进程使用,因此该进程无法访问此文件”
文件xxx正在由另一进城使用,这种问题出现有一种原因: 就是同一个线程重打开文件,但是没有关闭的情况下,再次读取的时候抛出异常. 如下的代码为错误代码:
- iOS_SN_基于AFNetworking3.0网络封装
转发文章,原地址:http://www.henishuo.com/base-on-afnetworking3-0-wrapper/?utm_source=tuicool&utm_medium= ...