题目链接:

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的更多相关文章

  1. [ACM] hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...

  2. HDU 4405 Aeroplane chess(概率dp,数学期望)

    题目 http://kicd.blog.163.com/blog/static/126961911200910168335852/ 根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什 ...

  3. HDU 4405 Aeroplane chess 概率DP 难度:0

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...

  4. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  5. hdu 4405 Aeroplane chess(简单概率dp 求期望)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. hdu 4405 Aeroplane chess (概率DP)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  7. hdu 4405 Aeroplane chess(概率+dp)

    Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...

  8. 【HDU4405】Aeroplane chess [期望DP]

    Aeroplane chess Time Limit: 1 Sec  Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...

  9. 【刷题】HDU 4405 Aeroplane chess

    Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...

随机推荐

  1. js实现弹出框的拖拽

    //HTML部分 <div class="wrap"></div> <div class="popUpBox"> <d ...

  2. React-Native使用极光进行消息推送

    推送作为APP几乎必备的功能,不论是什么产品都免不了需要消息推送功能,一般做RN开发的可能都是前端出身(比如我),关于android ios 都不是很懂

  3. CTF-安恒18年十一月月赛部分writeup

    安恒十一月月赛writeup 昨天做了一下十一月的题目,不才只做出来几道 签到web1 这个是十月的原题,因为忘了截图所以只能提供思路 Web消息头包含了登陆框的密码 输入密码后进入上传页面,上传一句 ...

  4. 【转】netty源码分析之LengthFieldBasedFrameDecoder

    原文:https://www.jianshu.com/p/a0a51fd79f62 拆包的原理 关于拆包原理的上一篇博文 netty源码分析之拆包器的奥秘 中已详细阐述,这里简单总结下:netty的拆 ...

  5. Oracletop10物理段

    Oracletop10物理段 select owner, name, type, mega, tbs from (select owner, case when segment_type = 'LOB ...

  6. 对Dataguard的三种模式的理解

    模式1:最大可保护模式: 必须同步. 模式2:最大可用性模式: 能同步就同步,不能同步就不同步. 模式3:最大性能模式: 异步模式.

  7. PosgreSQL 9.0 High Performance中文版瑕疵

    磨砺技术珠矶,践行数据之道,追求卓越价值 回到上一级页面: PostgreSQL杂记页     回到顶级页面:PostgreSQL索引页 发表此文不是为了吐槽,而是为了防止更多的受害者出现啊,拿到书后 ...

  8. CF248E Piglet's Birthday

    题面 题意翻译 给定$n$个货架,初始时每个上面有$a[i]$个蜜罐. 有$q$次操作,每次操作形如$u,v,k$,表示从货架$u$上任意选择$k$个蜜罐试吃(吃过的也还能吃),吃完后把这$k$个蜜罐 ...

  9. 2_C语言中的数据类型 (五)char

    1.1       char类型 1.1.1          char常量,变量 char c:定义一个char变量 ‘a’,char的常量 Char的本质就是一个整数,一个只有1个字节大小的整数 ...

  10. 【译】2017年要学习的三个CSS新特性

    这是翻译的一篇文章,原文是:3 New CSS Features to Learn in 2017,翻译的不是很好,如有疑问欢迎指出. 新的一年,我们有一系列新的东西要学习.尽管CSS有很多新的特性, ...