题意:沿着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. VUE 使用axios请求第三方接口数据跨域问题解决

    VUE是基于node.js,所以解决跨域问题,设置一下反向代理即可. 我这里要调用的第三方接口地址为 http://v.juhe.cn/toutiao/index?type=top&key=1 ...

  2. 联想电脑硬盘保护系统EDU8.0.1iso安装

    管理306机房4年了,15年我带领的第一批学生参加吉林省职业院校技能大赛的时候,领导把这个机房交给我负责.那个时候这个机房的机器是全校的顶配,30台DELL16G内存,2T硬盘,I7处理器,后面是6组 ...

  3. 【React Native错误集】Android error “Could not get BatchedBridge, make sure your bundle is packaged properly” on start of app

    问题1:Android error “Could not get BatchedBridge, make sure your bundle is packaged properly” on start ...

  4. PHP如何查找一列有序数组是否包含某值(二分查找)

    问题:对于一列有序数组,如何判断给出的一个值,该值是否存在于数组. 思路:判断是否存在,最简单是,直接循环该数组,对每一个值进行比较.但是对于有序数组来说,这样写就完全没有利用好“有序”这一特点. 所 ...

  5. 图的Prim,Kruskal,Dijkstra,Floyd算法

    代码部分有点问题,具体算法没问题, 最近期末考,要过段时间才会修改 //邻接矩阵,具体情况看上一篇的图的实现template<class T>class MGraph {public:   ...

  6. Redis的增删改查 c# key value类型和hash map 类型

    using Newtonsoft.Json; using StackExchange.Redis; using System; using System.Collections.Generic; us ...

  7. Java中很少用的CopyOnWriteArrayList

    类注释 /** * A thread-safe variant of {@link java.util.ArrayList} in which all mutative * operations ({ ...

  8. FTP 服务器在WIN10上的搭建及服务端下载文件实例

    1.搭建 (1)控制面板--->程序----->将FTP服务器打勾 (2)输入iis,或者右键桌面-->管理-->服务和应用程序--->internet informat ...

  9. thinkphp的增删改查命令 - (mysql-thinkphp) (4)

    方法1,在namespace下面加2行 use think\Controller; use think\Db; 1.查询所有结果 $res = Db::query("select * fro ...

  10. Linux:Shell-Bash基本功能

    1.历史命令 history [选项] [历史命令保存文件] 选项:-c  清空历史命令 -w 把缓存中的历史命令写入历史命令保存文件 ~/.bash_history 历史命令默认保存1000条,可以 ...