http://acm.hdu.edu.cn/showproblem.php?pid=4405

明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优

设E[i]为分数为i时还需要走的步数期望,j为某个可能投出的点数如果从i向i-j推导,我们并不能确定i的转移方向,因为可能有两个i-j有飞机其目的地是i,所以我们选择从i向i+j推导期望

如果设G[i]为分数为i时已经走过的步数期望,那么要确定G[i+j]需要知道P(i|i+j),也即转移到i+j的条件下从i转移来的概率,比较麻烦

由题意,设match[i]为i处飞机的目的地,则当match[i]存在时,E[i]=E[match[i]],否则E[i]=sigma((E[i+j]+1)*(1/6)),j in range(6)

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=1e5+5;
double e[maxn];
int match[maxn];
int n,m;
void init()
{
memset(e,0,sizeof(e));
memset(match,0,sizeof(match));
for(int i=0;i<m;i++){
int f,t;
scanf("%d%d",&f,&t);
match[f]=t;
}
}
int lt(int a){return min(a,n);}
void calc()
{
for(int i=n-1; i>=0; i--)
{
if(match[i]!=0)e[i]=e[lt(match[i])];
else
{
for(int j=1; j<=6; j++)
{
e[i]+=(e[lt(i+j)]+1)/6;
}
}
}
}
int main()
{
for(int ti=1; scanf("%d%d",&n,&m)==2&&(n||m); ti++)
{
init();
calc();
printf("%.4f\n",e[0]);
} return 0;
}

HDU 4405 Aeroplane chess 概率DP 难度:0的更多相关文章

  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)

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

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

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

  4. HDU 4405 Aeroplane chess 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...

  5. hdu 4405 Aeroplane chess (概率DP)

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

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

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

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

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

  8. ZOJ 3822 Domination 概率dp 难度:0

    Domination Time Limit: 8 Seconds      Memory Limit: 131072 KB      Special Judge Edward is the headm ...

  9. 【刷题】HDU 4405 Aeroplane chess

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

随机推荐

  1. Android图形显示之硬件抽象层Gralloc(hal 转)

    原文  http://blog.csdn.net/yangwen123/article/details/12192401 FrameBuffer驱动程序分析 文中介绍了Linux系统下的显示驱动框架, ...

  2. embed object以及video标签的区别以及使用

    embed object以及video标签的区别以及使用?

  3. poj2975(nim游戏取法)

    求处于必胜状态有多少种走法. if( (g[i]^ans) <= g[i]) num++; //这步判断很巧妙 // // main.cpp // poj2975 // // Created b ...

  4. Oracle Names - Oracle_SID /db_name instance_name service_names / service_name / sid / sid_name

    很多人还是困惑,下面再次尝试从几个不同角度区分一下: Oracle_SID / db_name, instance_name, service_names  / service_name, sid / ...

  5. Intent 隐式跳转,向下一个活动传递数据,向上一个活动返回数据。

    一.每个Intent只能指定一个action,多个Category. 使用隐式跳转,我们不仅可以跳转到自己程序内的活动,还可以启动其他程序的活动.使得Android多个程序之间的功能共享成为可能. 例 ...

  6. 基因组 de novo 组装原理

    Falcon软件的组装流程 为了错误校正,将原始子reads进行overlap 预组装和错误校正 错误校正后reads的overlap检测 overlap的过滤 从overlap构建图 从图构建con ...

  7. PC-1500的代码存入WAV文件

    目录 第1章保存    1 1.1 操作    1 1.2 波形说明    4 1.3 波形整形    5 1.4 压缩    8 第2章载入    9 2.1 操作    9 2.2 音量    9 ...

  8. robotframework笔记22

    创建测试库 支持的编程语言 机器人框架本身是用写的 Python 和自然的测试 库扩展它可以使用相同的实现 语言. 运行时框架上 Jython ,图书馆也可以 实现使用 Java . 纯Python代 ...

  9. 《JavaScript权威指南》读书笔记(四)

    日期:2015-12-06 事件传播:1.捕捉阶段2.运行阶段3.起泡阶段cookie和客户端持久性::HTML5引入了web应用缓存.LocalStorage.SessionStorage:使用XM ...

  10. JSON Viewer

    http://jsonviewer.codeplex.com/ jsoneditor https://github.com/josdejong/jsoneditor