题目链接:

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. 2.7 usb摄像头之usb摄像头描述符打印

    学习目标:参考lsusb源码,打印USB摄像头的设备描述符.配置描述符.接口联合描述符.端点描述符: 一.lsusb命令和源码 使用命令lsusb可以看看设备的id,并执行 # lsusb -v -d ...

  2. 【翻译】R 中的设计模式

    目录 R 中的设计模式 不动点算法 包装器模式 接口模式 柯里化(Currying) 闭包(Closures) 缓存模式 计数器模式 R 中的设计模式 本文翻译自 Design Patterns in ...

  3. 可用的ntp服务器

    操作系统中带的:time.windows.com 和 time.nist.gov  网上查到一个公共的:cn.ntp.org.cn 以上三个连接多次才成功一次,速度不好. 在移动电视盒子上有一个配置: ...

  4. 网络知识 ACL NAT IPv6

    第1章 ACL 访问控制列表 访问控制表(Access Control List,ACL),又称存取控制串列,是使用以访问控制矩阵为基础的访问控制方法,每一个对象对应一个串列主体. 访问控制表描述每一 ...

  5. ASP.NET MVC Bundles 之学习笔记

    在网页中,我们经常需要引用大量的javascript和css文件,在加上许多javascript库都包含debug版和经过压缩的release版(比如jquery),不仅麻烦还很容易引起混乱,所以AS ...

  6. 2018年美国大学生数学建模竞赛(MCM/ICM) 比赛心得

    话不多说,题目先上: 这是我们这次选择的题目,说说建模的那些事! 美赛的时间和国赛挑战杯时间略有不同,貌似多的一天是为了让我们对文章进行一个翻译吧QAQ 建议参加美赛的同学可以参照此计划进行 Day0 ...

  7. [原]Asp.net Core 2.1.2 测试成功Ajax上传文件新解法

    利用layui框架可以上传文件调试拦截成功! [HttpPost] public IActionResult Method1(IFormFile file) { return Json(new{suc ...

  8. linux 查询管道过滤,带上标题字段

    linux查询过滤, 带上标题字段例: 一个简单的查询 ps -e | grep httpd 上面经过grep 过滤后, 标题没了, 但是为了看上去更方便,有标题字段看起来更方便一些, 那么可以按下面 ...

  9. 用adb来修改android嵌入式设备的system只读目录下的东西

    转的一篇: 以修改hosts文件为例: 由于某些原因,可能需要指定域名对应的IP地址.Android是基于Linux的系统,与Linux类似,通过hosts文件来设置. 在Android下,/etc是 ...

  10. UNITY_资源路径与加载外部文件

    UNITY_资源路径与加载外部文件 https://www.tuicool.com/articles/qMNnmm6https://blog.csdn.net/appppppen/article/de ...