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 ...
随机推荐
- hdu 5423 Rikka with Tree(dfs)
Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...
- PCM文件格式简单介绍
PCM文件格式简单介绍 PCM文件:模拟音频信号经模数转换(A/D变换)直接形成的二进制序列,该文件没有附加的文件头和文件结束标志.Windows的Convert工具能够把PCM音频格式的文件转换成M ...
- 2.4 Git 基础 - 撤消操作
2.4 Git 基础 - 撤消操作 撤消操作 任何时候,你都有可能需要撤消刚才所做的某些操作.接下来,我们会介绍一些基本的撤消操作相关的命令.请注意,有些撤销操作是不可逆的,所以请务必谨慎小心,一旦失 ...
- .Net的PDF转图片
用的是破解版的 O2S.Components.PDFRender4NET.dll 插件, 简单引用即可 public static class PdfToImage { , , ) { try { / ...
- js实现楼层效果
今天自己写个楼层效果,有一点烦躁,小地方犯错误.各位大神来修改不足啊!!! <!DOCTYPE html><html lang="en"><head& ...
- <转>请戒掉成功学和正能量,那是麻痹人的毒药 | 新知
非常不幸的是,这将是一场非常糟糕的演说.我不想骗你们,你们从我这里几乎什么也学不到.你们在离开的时候肯定会感到失望,你们的生活并不会得到改善. 更糟糕的是,你还会意识到生活的本质毫无意义,你的一切努力 ...
- C# 操作 Excel
1.NOIP (功能齐全,评价较高) http://www.codeproject.com/Tips/813187/Csharp-Read-and-write-Excel-xls-and-xlsx-f ...
- memcached介绍及基本使用
一:概念 memcached是LiveJournal旗下Danga Interactive 公司的Brad Fitzpatric 为首开发的一款软件.现在已成为mixi,hatena,facebook ...
- window.onload,<body onload="function()">, document.onreadystatechange, httpRequest.onreadystatechang
部分内容参考:http://www.aspbc.com/tech/showtech.asp?id=1256 在开发的过程中,经常使用window.onload和body onload两种,很少使用do ...
- js delete 用法
1,对象属性删除 function fun(){ this.name = 'mm'; } var obj = new fun(); console.log(obj.name);//mm delet ...