博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 4405 Aeroplane chess(概率+dp)
阅读量:6259 次
发布时间:2019-06-22

本文共 2012 字,大约阅读时间需要 6 分钟。

Problem Description
Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. 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 1,2,3,4,5,6). 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 (0
<=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.

 

Input
There are multiple test cases. 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

 

Output
For each test case in the input, you should output a line indicating the expected dice throwing times. Output should be rounded to 4 digits after decimal point.

 

 
Sample Input
2 08 32 44 57 80 0

 

 
Sample Output
1.1667 2.3441

 

 
Source
 

 这道题适合从后面开始dp。将能跳的格子标志了,然后从n-1开始dp。具体看代码吧,不知道怎么说了。。。

 

1 #include
2 #include
3 #include
4 using namespace std; 5 #define N 100006 6 int n,m; 7 double dp[N]; 8 int vis[N]; 9 int main()10 {11 while(scanf("%d%d",&n,&m)==2 && n+m){12 memset(vis,-1,sizeof(vis));13 memset(dp,0,sizeof(dp));14 for(int i=0;i
=0;i--){20 if(vis[i]!=-1){21 dp[i]=dp[vis[i]];22 }else{23 for(int j=1;j<=6;j++){24 dp[i]+=dp[i+j]/6;25 }26 dp[i]+=1.0;27 }28 }29 printf("%.4lf\n",dp[0]);30 }31 return 0;32 }
View Code

 

转载地址:http://fsqsa.baihongyu.com/

你可能感兴趣的文章
MySQL也有潜规则 – Select 语句不加 Order By 如何排序?
查看>>
搭建SolrCloud的详细步骤
查看>>
svn的安装与使用
查看>>
基于Linux下Iptables限制BT下载的研究
查看>>
Android对话框-中篇-之建立自己的对话框
查看>>
华为交换机VRP用户界面配置及Telnet登录实验
查看>>
作为一个程序员我最大的遗憾
查看>>
《SolidWorks 2012中文版从入门到精通》一6.5 综合实例——斜齿圆柱齿轮
查看>>
storm集群的监控
查看>>
RHCE 6.0学习笔记-2 RHEL 6 使用光盘配置本地YUM源
查看>>
Mongodb定期备份
查看>>
Confluence 6 数据库设置
查看>>
刨根问底-struts-怎么加载配置的相应的信息
查看>>
解决mysql数据库大小写敏感问题
查看>>
jsp页面组成
查看>>
LCS记录
查看>>
C++开源跨平台类库集
查看>>
everything搜索工具小技巧
查看>>
一个 Sql语句优化的问题- STATISTICS 统计信息
查看>>
你不知道的KVO的内部实现
查看>>