HDU4405-Aeroplane chess(可能性DP需求预期)
Aeroplane chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1182 Accepted Submission(s): 802
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.
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.
2 0
8 3
2 4
4 5
7 8
0 0
1.1667
2.3441
#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int maxn = 100000+10;
double dp[maxn];
map<int,int> t;
map<int,int> flight;
int n,m;
void dfs(int sta,int x){
if(t[x]==0){
flight[sta] = x;
}else{
dfs(sta,t[x]);
}
}
void init(){
for(map<int,int>::iterator it = t.begin(); it != t.end(); it++){
dfs(it->first,it->second);
}
}
int main(){ while(cin >> n >> m && n+m){
t.clear();
flight.clear();
while(m--){
int a,b;
scanf("%d%d",&a,&b);
t[a] = b;
}
init();
dp[n] = 0;
for(int i = n-1; i >= 0; i--){
dp[i] = 1;
for(int k = 1; k <= 6; k++){
if(i+k <= n){
if(flight[i+k]==0){
dp[i] += dp[i+k]/6;
}else{
dp[i] += dp[flight[i+k]]/6;
} }
}
}
printf("%.4lf\n",dp[0]); }
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
HDU4405-Aeroplane chess(可能性DP需求预期)的更多相关文章
- UVA 10529 Dumb Bones 可能性dp 需求预期
主题链接:点击打开链接 题意: 要在一条直线上摆多米诺骨牌. 输入n, l, r 要摆n张排,每次摆下去向左倒的概率是l, 向右倒的概率是r 能够採取最优策略.即能够中间放一段.然后左右两边放一段等, ...
- [hdu4405]Aeroplane chess(概率dp)
题意:某人掷骰子,数轴上前进相应的步数,会有瞬移的情况,求从0到N所需要的期望投掷次数. 解题关键:期望dp的套路解法,一个状态可以转化为6个状态,则该状态的期望,可以由6个状态转化而来.再加上两个状 ...
- HDU4405 Aeroplane chess(期望dp)
题意 抄袭自https://www.cnblogs.com/Paul-Guderian/p/7624039.html 正在玩飞行棋.输入n,m表示飞行棋有n个格子,有m个飞行点,然后输入m对u,v表示 ...
- HDU4405 Aeroplane chess (概率DP,转移)
http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落 ...
- 【HDU4405】Aeroplane chess [期望DP]
Aeroplane chess Time Limit: 1 Sec Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...
- hdu4405 Aeroplane chess
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- [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
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- HDU-4405 Aeroplane chess
http://acm.hdu.edu.cn/showproblem.php?pid=4405 看了一下这个博客http://kicd.blog.163.com/blog/static/12696191 ...
随机推荐
- 【C++探索之旅】第一部分第二课:C++编程的必要软件
内容简介 1.第一部分第二课:C++编程的必要软件 2.第一部分第三课预告:第一个C++程序 C++编程的必要软件 经过上一课之后,大家是不是摩拳擦掌,准备大干一场了呢. 这一课我们来做一些C++开发 ...
- 这两个成员函数inline重新virtual种类
inlineType表示在编译时扩展功能,随着在函数调用的函数体而出替换函数调用:和vitual它是c++多态的必要条件,但为了表现出多态性,您将需要等到执行,要知道什么是真正的函数调用.从表面上看这 ...
- Connect2015 简要整理
2015 简要整理 去年 Connect(); 2014 Visual Studio Contact(); 直播笔记 对于我个人来说,今年 Connect(); 的三个重要发布: ASP.NET 5 ...
- IIS7和IIS7.5备份和还原的方法
windows2008的iis配置备份和iis6不同,在iis7中没有了6原来的保存配置xml的选项,而采用的是dos命令来进行iis7的备份.以下是win2008上iis7备份的方法. 首先打开CM ...
- HDU4540+DP
简单题... dp[ i ][ j ] 表示第 i 行取第 j 个数的MinVal /* DP&简单题 */ #include<stdio.h> #include<strin ...
- 【软件使用技巧】PL/SQL Developer实现双击table询
二手plsql都知道,在表名默认双击[开展/关闭]. 习惯了MySql Workbench要么Sqlserver Management Studio无法适应其他管理工具. 直接在溶液: Tools - ...
- 颜色(color)转换为三刺激值(r/g/b)(干股)
//颜色转换 ##665522 - 三色值 + (UIColor *)setFontColorWithString:(NSString *)color { NSString *cString ...
- 3D-HEVC的TAppDecorder
一.点击项目右键设为启动项目. 二.配置文件 右键点击属性->点配置属性的Debugging,在command arguments一栏填上编码时生成的.bit文件和希望解码后文件的命名,在wor ...
- Bubbles Shader in Houdini泡泡泡泡泡泡泡泡泡泡
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY3Vja29u/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/d ...
- 【代码优化】当许多构造函数的参数,请考虑使用builder模式
静态工厂和构造具有共同的局限性:我们不能扩展到大量的非常好的可选参数. 1.对于多个可选參数的构造器.我们都习惯採用重叠构造器模式.比方一个參数的构造器调用2个參数的构造器. 2个參数的构造器 ...