HDU 4405: Aeroplane chess
类型:概率DP
题意:一条直线下飞行棋,色子六个面等概率。同时存在一些飞机航线,到了某个点可以直接飞到后面的另一个点,可以连飞,保证一个点至多一条航线。求到达或者超过终点 所需要 掷色子的期望次数。
思路:
如果可以飞,那么从这个点到终点的期望次数 等于 飞到的那个点 到终点的期望次数。 否则,就是掷一次色子,然后后面六个点到终点的期望次数 求平均 +1;
换种表示:
if (canFly) dp[now] = dp[flyTo];
else dp[now] = (dp[now+1]+dp[now+2]+...+dp[now+6]) / 6;
代码:
#include <cstdio>
#include <cstring>
#define N 100010
#define M 1010 double dp[N];
int airLine[N]; int main() {
int n, m;
while (scanf("%d%d", &n, &m) != EOF) {
if (n == && m == ) break;
memset(airLine, -, sizeof(airLine));
for (int i = ; i < m; i++) {
int u, v;
scanf("%d%d", &u, &v);
airLine[u] = v;
} for (int i = n; i < n+; i++) dp[i] = ;
for (int i = n-; i >= ; i--) {
if (airLine[i] != -) {
dp[i] = dp[airLine[i]];
continue;
}
dp[i] = ;
for (int j = ; j <= ; j++) {
dp[i] += (1.0/6.0)*dp[i+j];
}
}
printf("%.4lf\n", dp[]);
}
return ;
}
HDU 4405: Aeroplane chess的更多相关文章
- HDU 4405:Aeroplane chess(概率DP入门)
http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description Hzz loves ...
- 【HDOJ】【4405】Aeroplane chess飞行棋
概率DP/数学期望 kuangbin总结中的第4题 啊还是求期望嘛……(话说Aeroplane chess这个翻译怎么有种chinglish的赶脚……) 好像有点感觉了…… 首先不考虑直飞的情况: f ...
- hdu4405:Aeroplane chess
题目大意:有编号为0-n的格子,从0开始,扔骰子扔到几就走几格.有m个瞬移点,每个点可以从格x直接飞到格y,若瞬移到另一个瞬移点可以继续瞬移.求到达格n的期望扔骰子次数. 题解:期望DP入门好题.网上 ...
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
- 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) ...
- [ACM] hdu 4405 Aeroplane chess (概率DP)
Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 ...
- Aeroplane chess(HDU 4405)
Aeroplane chess Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 4405 Aeroplane chess(概率+dp)
Problem Description Hzz loves aeroplane chess very much. The chess map contains N+ grids labeled to ...
随机推荐
- 【数论分块】bzoj2956: 模积和
数论分块并不精通……第一次调了一个多小时才搞到60pts:因为不会处理i==j的情况,只能枚举了…… Description $\sum_{i=1}^{n}\sum_{j=1 \land i \not ...
- node中的定时任务
node-schedule每次都是通过新建一个scheduleJob对象来执行具体方法. 时间数值按下表表示 * * * * * * ┬ ┬ ┬ ┬ ┬ ┬ │ │ │ │ │ | │ │ │ │ │ ...
- 使用 Python 编写登陆接口
# 使用 Python 编写登陆接口# Create Date: 2017.10.31 Tuesday# Author: Eric Zhao# -*- coding:utf-8 -*-'''编写登陆接 ...
- poj-3278 catch that cow(搜索题)
题目描述: Farmer John has been informed of the location of a fugitive cow and wants to catch her immedia ...
- 【转】MySQL innodb_autoinc_lock_mode 详解 ,并发插入时主键冲突的解决方案
本文转载于 http://www.cnblogs.com/JiangLe/p/6362770.html innodb_autoinc_lock_mode这个参数控制着在向有auto_increment ...
- Linux学习-什么是进程 (process)
触发 任何一个事件时,系统都会将他定义成为一个进程,并且给予这个进程一个 ID ,称为 PID,同时依据启发这个进程的用户与相关属性关系,给予这个 PID 一组有效的权限设定.从此以后,这 个 PID ...
- day37-- &MySQL step1
m1.客户端与数据库服务器端是通过socket来交互数据,对数据库的理解:数据库就是一个文件夹,表就类比文件.m2.常用语句#查看数据库show databases:#创建数据库create data ...
- luogu3203 [HNOI2010]弹飞绵羊
lct裸题 #include <iostream> #include <cstdio> using namespace std; int n, ski[200005], m, ...
- Markdown,后缀MD
Markdown 算是一门新兴语言,现在 7-8 岁了吧.它设计的初衷就是让写字的人专注于写字,用纯文本简单的符号标记格式,最后再通过工具转换成鬼畜的 HTML/XHTML.如果你玩过 wikiped ...
- python面向对象、模块讲解
(1)模块的介绍: 1.什么是模块 模块是一系列功能的集合体 常见的模块形式(自定义模块.第三方模块.内置模块): 1.一个module.py文件就是一个模块,文件名是module.py,而模 ...