hdu4405Aeroplane chess(概率与期望dp)
Aeroplane chess
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 4239 Accepted Submission(s):
2674
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<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.
line indicating the expected dice throwing times. Output should be rounded to 4
digits after decimal point.
8 3
2 4
4 5
7 8
0 0
2.3441
similar problems for you: 6032 6031 6030 6029 6028
/*
本题是扔色子,其实概率也就是1/6,但是本题还有一个不同的地方,那就是可以飞行
比如从a飞到b,而不用扔色子,这些条件都会影响我们做题的方法
首先定义状态dp[i]表示处于i位置时所扔色子次数的期望,可知dp[n] = 0。
然后找找转移方程,那根据题意可知,i位置要么是可以飞行的,要么就不是
所以当i点可以飞行时,dp[i] = dp[fly[i]],其中fly[i]代表i飞行到的另一个点
否则,依据期望的定义,dp[i] = 1/6*dp[i+j] + 1,其中j = 1,2...6,代表扔色子可能的点数
最后别忘了加1,代表本次需要扔一次色子。最后,规划方向依然是从后往前,答案就是dp[0]。
*/
#include<iostream>
#include<cstdio>
#include<cstring> #define N 100005 using namespace std;
double dp[N];
int fly[N]; int main()
{
int n,m;
while(~scanf("%d%d",&n,&m) && (n||m))
{
for(int i=;i<=n;i++)
{
dp[i]=;fly[i]=-;
}
int a,b;
for(int i=;i<=m;i++)
{
scanf("%d%d",&a,&b);
fly[a]=b;
}
for(int i=n-;i>=;i--)
{
if(fly[i]!=-) dp[i]=dp[fly[i]];
else
{
for(int j=;j<=;j++)
{
if(i+j>n) dp[i]+=1.0/*dp[n];
else dp[i]+=1.0/*dp[i+j];
}++dp[i];
}
}
printf("%.4f\n",dp[]);
}
return ;
}
hdu4405Aeroplane chess(概率与期望dp)的更多相关文章
- 【BZOJ-4008】亚瑟王 概率与期望 + DP
4008: [HNOI2015]亚瑟王 Time Limit: 20 Sec Memory Limit: 512 MBSec Special JudgeSubmit: 832 Solved: 5 ...
- 概率和期望dp
概率和期望dp 概率和期望好神啊,完全不会. 网上说概率要顺着推,期望要逆着推,然而我目前做的概率期望题正好都与此相反2333 概率: 关于概率:他非常健康 初中概率题非常恐怖.现在来思考一道题: ...
- 【CodeForces】913 F. Strongly Connected Tournament 概率和期望DP
[题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之 ...
- 概率与期望dp相关
概率与期望dp 概率 某个事件A发生的可能性的大小,称之为事件A的概率,记作P(A). 假设某事的所有可能结果有n种,每种结果都是等概率,事件A涵盖其中的m种,那么P(A)=m/n. 例如投掷一枚骰子 ...
- 【算法学习笔记】概率与期望DP
本文学习自 Sengxian 学长的博客 之前也在CF上写了一些概率DP的题并做过总结 建议阅读完本文再去接着阅读这篇文章:Here 前言 单纯只用到概率的题并不是很多,从现有的 OI/ACM 比赛中 ...
- hdu4405Aeroplane chess 概率dp水题
//从0到n有n+1个格子 //对于格子i,掷一次骰子的数为x.那么能够从位置i到位置i+x //格子之间有连线,假设格子a和b有连线,那么从a到b不用掷骰子 //求从0到n的骰子掷的次数的期望 // ...
- HDU4405 Aeroplane chess 飞行棋 期望dp 简单
http://acm.hdu.edu.cn/showproblem.php?pid=4405 题意:问从起点到终点需要步数的期望,1/6的概率走1.2.3.4.5.6步.有的点a有路可以直接到b, ...
- 概率及期望DP小结
资源分享 26 个比较概率大小的问题 数论小白都能看懂的数学期望讲解 概念 \(PS\):不需要知道太多概念,能拿来用就行了. 定义 样本(\(\omega\)):一次随机试验产生的一个结果. 样本空 ...
- 【BZOJ-3450】Tyvj1952Easy 概率与期望DP
3450: Tyvj1952 Easy Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 468 Solved: 353[Submit][Status] ...
随机推荐
- (转)Arcgis for javascript实现百度地图ABCD marker的效果
概述: 在我的博客中,有一篇相关的文章,这段时间,有很多人问我求源码,只是时间过去已长,源代码已找不到,乘着这个9.3放假,又重新实现了下,并相关代码做了优化,在此贴出来,方便大家使用. 相关文章地址 ...
- fuel一键部署
1. 所需物理主机的要求如下 内存:8GB+,推荐16GB: 磁盘:50GB+: 物理机OS:ubuntu-desktop-amd64 14.04(推荐) 或windows64位 物理机安装软件:安装 ...
- 1、DataGridView
DataGridView赋值后 通过RowPostPaint事件绘制行号 private void AddXh() { DataGridViewTextBoxColumn col = new Data ...
- vue移动端地址三级联动组件(二)
继续上一篇: 子组件css: <style scoped lang="less"> #city { width: 100%; height: 100%; positio ...
- JeePlus 工作流版本 sping mvc oa crm erp java html5 源码
https://shop108220642.taobao.com/search.htm?spm=2013.1.w5002-5297459241.1.mnhAZ5&search=y http:/ ...
- CentOS7下安装ELK三件套
ELK用于分布式收集,然后elasticsearch用于分析数据,在Kibana中可以查看数据.报表. 目前公司日志数据量暂时不使用elasticsearch集群,只是用的elasticsearch单 ...
- python--(十五步代码学会进程)
python--(十五步代码学会进程) 一.进程的创建 import time import os #os.getpid() 获取自己进程的id号 #os.getppid() 获取自己进程的父进程id ...
- ZOJ 3233 Lucky Number
Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...
- (45). Spring Boot MyBatis连接Mysql数据库【从零开始学Spring Boot】
大家在开发的时候,会喜欢jdbcTemplate操作数据库,有喜欢JPA操作数据库的,有喜欢MyBatis操作数据库的,对于这些我个人觉得哪个使用顺手就使用哪个就好了,并没有一定要使用哪个,个人在实际 ...
- iOS学习笔记17-FMDB你好!
上一节我已经介绍了SQLite的简单使用,不了解的可以提前去看一下iOS学习笔记16-数据库SQLite,这节我们来讲下FMDB. 一.FMDB介绍 FMDB是一种第三方的开源库,FMDB就是对SQL ...