HDU 4405 Aeroplane chess 期望dp
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4405
Aeroplane chess
Time Limit: 2000/1000 MS (Java/Others)Memory Limit: 32768/32768 K (Java/Others)
#### 问题描述
> 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
> Please help Hzz calculate the expected dice throwing times to finish the game.
#### 输入
> 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 The input end with N=0, M=0.
输出
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.
样例输入
2 0
8 3
2 4
4 5
7 8
0 0
样例输出
1.1667
2.3441
题意
飞行棋,每次投掷骰子,(1-6等概率),按骰子大小前进,其中有若干个飞机场(a,b),可以从a直接传送到b,现从0点出发,问到达>=N的点需要的期望步数。
题解
期望dp入门:
全期望公式:E[x]=sigma(pi*E[xi]).
有飞机场的话:E[a]=E[b]。
否则:E[i]=sigma(1/6*(E[i+x]+1)).
代码
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-8;
const double PI = acos(-1.0);
//start----------------------------------------------------------------------
const int maxn=101010;
///dp[i]表示在i点,到达终点还需几步
///期望一般逆推求,比如这一题,你已知的状态是终点而不是起点。
double dp[maxn];
int mp[maxn];
int n,m;
void init(){
clr(mp,-1);
clr(dp,0);
}
int main() {
while(scf("%d%d",&n,&m)==2&&n){
init();
rep(i,0,m){
int u,v;
scf("%d%d",&u,&v);
mp[u]=v;
}
for(int i=n-1;i>=0;i--){
///有飞机场,直接飞过去
if(mp[i]!=-1){
dp[i]=dp[mp[i]];
continue;
}
///掷骰子,全期望公式
for(int x=1;x<=6;x++){
dp[i]+=1.0/6*(dp[i+x]+1);
}
}
prf("%.4lf\n",dp[0]);
}
return 0;
}
//end-----------------------------------------------------------------------
HDU 4405 Aeroplane chess 期望dp的更多相关文章
- [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://kicd.blog.163.com/blog/static/126961911200910168335852/ 根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什 ...
- HDU 4405 Aeroplane chess 概率DP 难度:0
http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- hdu 4405 Aeroplane chess(简单概率dp 求期望)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4405 Aeroplane chess(概率+dp)
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...
- 【HDU4405】Aeroplane chess [期望DP]
Aeroplane chess Time Limit: 1 Sec Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...
- 【刷题】HDU 4405 Aeroplane chess
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...
随机推荐
- NRF52832初步使用
开发环境搭建 开发环境涉及到协议栈SDK版本.keil PACK版本的匹配问题,目前测试通过的环境如下: windows系统:win10 硬件:NRF52832测试板.JLINK-V8仿真器 Keil ...
- 【转】Netty 拆包粘包和服务启动流程分析
原文:https://www.cnblogs.com/itdragon/archive/2018/01/29/8365694.html Netty 拆包粘包和服务启动流程分析 通过本章学习,笔者希望你 ...
- css文字环绕
html: <div class="wrap-div-topSpacer"></div> <div class="wrap-div" ...
- 一维码UPC A简介及其解码实现(zxing-cpp)
UPC(Universal Product Code)码是最早大规模应用的条码,其特性是一种长度固定.连续性的条 码,目前主要在美国和加拿大使用,由于其应用范围广泛,故又被称万用条码. UPC码仅可 ...
- [C/C++11]_[初级]_[std::bind介绍和使用]
场景 1.C++11 引入了std::function 对象, 这个对象可以通过std::bind封装所有的函数, 并通过代理调用这个std::function的方式调用这个函数. 比如通过统一的方式 ...
- 【HNOI2013】消毒
题面 题解 当只有二维时,就是一个二分图匹配的板子题 三维的时候就很好做了,暴力枚举一维的情况,因为\(\min(x,y,z) = \sqrt{5000} < 18\),于是时间复杂度有保证 代 ...
- 【LG3240】[HNOI2015]实验比较
题面 洛谷 题解 30pts 爆搜即可. 100pts 题意描述里有一句:"对每张图片\(i\),小\(D\)都最多只记住了某一张质量不比\(i\)差的另一张图片\(K_i\)." ...
- 有哪些 Bootstrap 的学习案例?
bootstrap经典实用案例 bootstrap经典实用案例(非常详细),从菜鸟到高手的过程是艰辛的,你渴望救助.这本教程就是你无言的助手,默默的帮你到永远. 带奋斗一起飞翔,因为有了它,让我拥有理 ...
- restful framework之序列化组件
一.Django自带序列化组件 from django.core import serializers def test(request): book_list = Book.objects.all( ...
- HTML中内联元素与块状元素介绍
常用的块级元素: address , center , div , dl ,, form , h1 , h2 , h3 , h4 , h5 , h6 , menu , ol , p , table , ...