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 ...
 
随机推荐
- 如何安装CocoaPods
			
转自 http://www.99css.com/1321/ 在 iOS 项目开发中,经常会用到第三方的源代码,CocoaPods 就是为了方便管理这些源码的工具. 在官方教程里面,安装看起来非常简单 ...
 - Homebrew新一代OS X套件管理工具  高速安装Git
			
在Mac上安装一些开源程序,除了自己下下载.编译( ./configure && make && make install) 之外,通常最方便的选择就是用套件管理工具來 ...
 - install samba on crux without net.
			
1. 解压文件 tar -xvfz samba-.tar.gz 2. 进入目录 cd samba- 3. 配置 ./configure 4. 编译 make 5. 安装 make install
 - Redis的快照功能
			
引言: Redis是基于内存的数据库,同时也提供了若干持久化的方案,允许用户把内存中的数据,写入本地文件系统,以备下次重启或者当机之后继续使用.本文将描述如何基于Redis来设置这些功能. 快照的设 ...
 - avalon学习笔记一 列表及条件过滤
			
好长时间都没有更新博客了,不是因为没有学习新的东西,而是到了新的单位每天玩命加班实在是太累了!经过一年的努力吧,终于可以轻松一下了.废话少说,直接干货吧! 由于是学习阶段,就直接拿了公司的二级页面做了 ...
 - asp.net读取文件
			
context.Response.ContentType = "text/html"; string fullpath = context.Server.MapPath(" ...
 - .NET 笔试分享
			
最近一直在面试,每次面试前也不怎么准备,虽说碰到的题大部分都很简单的,但是在现场答题的时候由于自己紧张脑子就空了,一些题答的不是很好,所以只有每次回来的时候才能好好想想怎么答: 题大部分还是挺简单的, ...
 - UIView设置少于四个的圆角
			
最近的需求中有个label需要设置右下角为圆角,其余三个为直角,一开始用的是重写drawRect,然后用绘图重绘每个角的样子,计算起来还是麻烦 后来发现了下面的方法: UILabel *courseS ...
 - 关于发布DIPS的MVC项目的IIS 7.0环境配置的方法
			
本人技术笨拙,今天在发布DIPS的MVC4.0项目,并部署到IIS上,遇到各种问题.在查询相关资料后,最终得以解决,所以想把这个过程记录下来. 注:DIPS为一种非关系型数据库 首先,需要安装和注册D ...
 - js判断上传文件的类型和大小
			
//检测文件大小和类型 function fileChange(target){ //检测上传文件的类型 if(!(/(?:jpg|gif|png|jpeg)$/i.test(target.value ...