题意:沿着x轴从0走到大于等于N的某处,每一步的步数由骰子(1,2,3,4,5,6)决定,若恰好走到x轴上某飞行路线的起点,则不计入扔骰子数。问从0走到大于等于N的某处的期望的扔骰子次数。

分析:

1、dp[i]表示从位置i到终点期望的扔骰子次数。

2、很显然倒着往前推,因为从起点0开始,扔骰子的次数有很多种可能,难以计算,但是dp[N]很显然是0,不需要扔骰子即可到达终点。

3、假设当前位于位置i,根据骰子数可能到达的位置有i + j(j=1,2,3,4,5,6),到达其中每个位置的概率都是1/6,

与此同时继承了从所到达的位置到终点的所需扔的骰子数,即dp[i] += dp[i + j] / 6。

4、而从位置i到位置i+j是需要扔一次骰子的,所以 ++dp[i]。

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define lowbit(x) (x & (-x))
const double eps = 1e-8;
inline int dcmp(double a, double b){
if(fabs(a - b) < eps) return 0;
return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100000 + 10;
const int MAXT = 10000 + 10;
using namespace std;
int f[MAXN];
double dp[MAXN];
int main(){
int N, M;
while(scanf("%d%d", &N, &M) == 2){
if(!N && !M) return 0;
memset(f, 0, sizeof f);
memset(dp, 0, sizeof dp);
while(M--){
int x, y;
scanf("%d%d", &x, &y);
f[x] = y;
}
for(int i = N - 1; i >= 0; --i){
if(f[i]) dp[i] = dp[f[i]];
else{
for(int j = 1; j <= 6; ++j){
dp[i] += dp[i + j] / 6;
}
++dp[i];
}
}
printf("%.4f\n", dp[0]);
}
return 0;
}

  

HDU - 4405 Aeroplane chess(期望dp)的更多相关文章

  1. HDU 4405 Aeroplane chess 期望dp

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

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

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

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

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

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

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

  5. HDU 4405 Aeroplane chess (概率DP)

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

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

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

  7. hdu 4405 Aeroplane chess (概率DP)

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

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

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

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

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

  10. 【刷题】HDU 4405 Aeroplane chess

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

随机推荐

  1. Shiro登录身份认证(从SecurityUtils.getSubject().login(token))到Realm的doGetAuthenticationInfo

    ssm框架下,controller接收到登录请求交给Service并开始处理流程: 1.Service的login方法: @Service public class SysUserServiceImp ...

  2. 一、Linux&配置,依赖安装&Tomcat,Mysql,jdk安装

    基础知识: 1 OS Operation System 作用:控制硬件,服务软件 2 VMware虚拟机: 虚拟出一台计算机环境 配置两个虚拟网卡,适配器里查看 3 在虚拟机上安装操作系统Linux ...

  3. 题解 hdu4624 Endless Spin

    题目链接 题目大意: 有长度为\(n\)的区间,每次随机选择一段(左右端点都是整数)染黑,问期望多少次全部染黑. \(n\leq 50\) 设\(n\)个随机变量\(t_1,...,t_n\).\(t ...

  4. PAT (Advanced Level) 1136~1139:1136模拟 1137模拟 1138 前序中序求后序 1139模拟

    1136 A Delayed Palindrome(20 分) 题意:给定字符串A,判断A是否是回文串.若不是,则将A反转得到B,A和B相加得C,若C是回文串,则A被称为a delayed palin ...

  5. 第1节 IMPALA:8、shell交互窗口使用;9、外部和内部shell参数

    impala当中的元数据的同步的问题impala当中创建的数据库表,直接就可以看得到,不用刷新hive当中创建的数据库表,需要刷新元数据才能够看得到 因为impala的catalog的服务,我们需要通 ...

  6. Python 3.8 新功能【新手必学】

       Python 3.8 是 Python 编程语言的最新主要版本, 它包含许多新功能和优化.   Python 3.8 Python 3.8 的一些新功能包括: 1. 海象运算符   PS:很多人 ...

  7. lpwizard 生成的 allegro 封装中 .psx 文件使用方法。

    lpwizard 有时候生成 allegro 封装的时候会生成 .psx 文件,这个文件其实是脚本文件,用于某些特殊形状焊盘的处理. 具体的使用方法如下: 在Allegro中,选择 File > ...

  8. Oracle 中启用 scott 用户 的方法

    解锁scott: SQL> alter user scott account unlock 修改密码: SQL> alter user scott identified by tiger ...

  9. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 字体图标(Glyphicons):glyphicon glyphicon-info-sign

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...

  10. Exchange Server 2010邮件策略与遵从性

    本文档附带了一个附档,里面详细的描述了如何在Exchange Server 2010中配置如下内容: 1.邮件分类 2.免责申明 3.配置信息隔离墙 4.邮件审核 5.Exchange 2010与AD ...