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 ...
随机推荐
- 【Android进阶】关于PagerAdapter的使用方法的总结
PagerAdapter简介 PagerAdapter是android.support.v4包中的类,它的子类有FragmentPagerAdapter, FragmentStatePagerAdap ...
- std::string 不支持back
string s = "abc"; if ( s.back() == 'c' ) .... , 不支持back, 但是用VS2010好吧 后来发现, string的back/fr ...
- 【Java GUI】Java面板基础:JPanel
有两个面板,常见的面板(JPanel)和滚动面板(JScrollPane) Jpanel 面板是一种常见的容器,JPanel的作用是实现接口层次结构,面放入一些组件.也能够在上面绘画,将放有组件和有画 ...
- iOS_动态插入或删除行
终于效果图: 分MVC三层设计;自己定义的Cell有两种;一种是MainCell,由ModelArr提供数据源;还有一种是插入的cell,由代码创建,而且由另外一个数组供状态数据 数据源部分: wat ...
- css3制作一个漂亮的按钮
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFMAAAA4CAIAAAAO41POAAAGWklEQVRogeWabWwTdRzH/8EwMb6Q69
- iOS第三方库
热门iOS第三方库:看完,还敢自称”精通iOS开发”吗? 综合github上各个项目的关注度与具体使用情况,涵盖功能,UI,数据库,自动化测试,编程工具等类型,看完,还敢自称”精通iOS开发”吗? h ...
- java它们的定义jar套餐读Excel(这包括2003和2007)数据,和实例
使用java它们的定义jar套餐读excel数据支持excel2007和excel2003 在http://download.csdn.net/detail/u010792467/8079355下载所 ...
- mysql 解压缩和赋权
拉开拉链mysql紧凑根文件夹 注意ini配置文件的内容 basedir = D:\mysql-5.6.17-winx64 datadir = D:\mysql-5.6.17-winx64 por ...
- uva10067 Playing with Wheels 【建图+最短路】
题目:option=com_onlinejudge&Itemid=8&page=show_problem&problem=1008">uva10067 Play ...
- 初识 Cloudera Impala
Impala是Cloudera公司主导开发的新型查询系统,它提供SQL语义,能查询存储在Hadoop的HDFS和HBase中的PB级大数据.已有的Hive系统尽管也提供了SQL语义,但因为Hive底层 ...