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++ 类定义】
Description 编写基于对象的程序,求长方柱(Bulk)的体积.数据成员包括长(length).宽(width).高(heigth).体积,要求用成员函数实现下面的功能: (1)由键盘输入长方 ...
- SSh框架结构(Struts2.1+Hibernate4.0+Spring3.1)
一个.使用的工具 开发工具:My Eclipse 10.7以及对应的java开发工具 框架版本号:Struts2.1+Hibernate3+Spring3.0 数据库:MySql5.5 Mysql可视 ...
- [LeetCode141]Linked List Cycle
题目:Given a linked list, determine if it has a cycle in it. 判断一个链表是否有环 代码: /** * Definition for singl ...
- android 常见的解决(mdpi、hdpi 、xhdpi、xxhdpi )屏幕调整
查询到执行的system service后,就能够在dumpsys后面加上service的名字,查看指定的service信息. adb shell dumpsys activity adb shell ...
- asp.net模板控件示例
原文:asp.net模板控件示例 模板控件允许将控件数据与其表示形式相分离,模板化控件不提供用户界面. 编写它则是为了实现一个命名容器以及包含属性和方法可由宿主页访问的类,MSDN是这样解释的. 下面 ...
- 讲座:采用Store检查邮件(1)
讲座:采用Store检查邮件(1) 一.邮件接收的体系结构 JavaMail API中定义了一个java.mail.Store类,用于运行邮件的接收任务,该类的实例对象封装了某种邮件接收协议的底层实施 ...
- 如何使盘ISO图像文件
原创作品.从 "深蓝blog" 博客,欢迎转载,请务必注明转载的来源,权法律责任. 深蓝的blog:http://blog.csdn.net/huangyanlong/articl ...
- bzoj 3333: 排队计划 解决问题的方法
[原标题] 3333: 排队计划 Time Limit: 20 Sec Memory Limit: 128 MB Submit: 161 Solved: 71 [Submit][Status] D ...
- DuiVision开发教程(15)-DUI文本控制基础类
CControlBaseFont类是DuiVision支持所有基类的控件的文本属性. 此控件例如属性列表,下面: 物业名称 类型 说明 title 字符串 控件的显示标题 font 字体 控件的字体, ...
- StackExchange.Redis 使用 (一)
在StackExchange.Redis中最重要的对象是ConnectionMultiplexer类, 它存在于StackExchange.Redis命名空间中.这个类隐藏了Redis服务的操作细节, ...