HDU - 4405 Aeroplane chess(期望dp)
题意:沿着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)的更多相关文章
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- [ACM] hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...
- HDU 4405 Aeroplane chess(概率dp,数学期望)
题目 http://kicd.blog.163.com/blog/static/126961911200910168335852/ 根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什 ...
- HDU 4405 Aeroplane chess 概率DP 难度:0
http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- hdu 4405 Aeroplane chess(简单概率dp 求期望)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- hdu 4405 Aeroplane chess(概率+dp)
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...
- 【HDU4405】Aeroplane chess [期望DP]
Aeroplane chess Time Limit: 1 Sec Memory Limit: 32 MB[Submit][Stataus][Discuss] Description Hzz lov ...
- 【刷题】HDU 4405 Aeroplane chess
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled fr ...
随机推荐
- scrcpy投屏android手机到电脑
在mac os下 投票iPhone投屏是最简单不过了,只需要用Quicktime player就可以. 但是在mac下咱投屏android的手机呢,就需要用到scrcpy了. 1.打开终端,输入命令: ...
- springboot打包的问题可执行jar和不可执行jar
具体解释可以参看:https://www.cnblogs.com/liaojie970/p/9007577.html 如果只是想要依赖那么可以将springboot自带的打包插件换掉就可以了,换为如下 ...
- updatexml()报错注入
首先了解下updatexml()函数 UPDATEXML (XML_document, XPath_string, new_value); 第一个参数:XML_document是String格式,为X ...
- 小米xiaomi9 google play卡在检查信息
终于在今年淘汰掉用了三年的果6s,换了小米9 ,结果发现科学..上网后,可以正常打开google网页,却无法登陆,gmail也无法使用.一直卡在“正在核对信息”. 检查服务,小米9 全系列自带了谷歌框 ...
- Time Series_1_BRKA Case
Berkshire Hathaway (The most expensive stock ever in the world) 1.1 Download data require(quantmod) ...
- PHP+MySQL实现在线测试答题实例
这个实例主要给大家介绍如何使用jQuery+PHP+MySQL来实现在线测试题,包括动态读取题目,答题完毕后台评分,并返回答题结果. 读取答题列表: $sql = "select * fro ...
- Masonry与UITableView+FDTemplateLayoutCell搭配使用
打个小广告:本人开发了一个宠物相关的App,欢迎大家下载体验~ 下载二维码: 进入正文: 之前发过一篇博客,也是对这两个的练习使用,但是之后遇到些问题,所以删除重写了.抱歉 Masonry是一款轻量级 ...
- Lesson 46 Hobbies
Who, according to the authour, are 'Fortune's favoured children'? A gifted American psychologist has ...
- python进阶强化学习
最近学习了慕课的python进阶强化训练,将学习的内容记录到这里,同时也增加了很多相关知识. 主要分为以下九个模块: 基本使用 迭代器和生成器 字符串 文件IO操作 自定义类和类的继承 函数装饰器和类 ...
- 小程序通过web-view实现与h5页面之间的交互
在小程序端使用web-view内嵌网页,通过 src 携带参数,通过 @message 接收h5传回的数据 <template> <view> <web-view :sr ...