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 ...
随机推荐
- MySQL - INSERT 集合
范例1: INSERT INTO t_table SELECT ot.* FROM t_other_table ot WHERE ot.is_sent = ? and ot.insert_time & ...
- Ajax原生代码
Ajax传数据有两种方式:get/post.下面是前台的get/post方式的代码. //------------原生--------- function AjaxGET(){ //第一步 调用Aja ...
- eclipse使用技巧的网站收集——转载(二)
写代码离不开文本编辑器,看代码也离不开,iar和keil编辑和阅读简直一般般了,因此使用eclipse可以看看代码,提高效率.网上有几个博客的文章,这里收集一下,以备忘. 以下文章转载自:http:/ ...
- HDU - 1496 Equations (hash)
题意: 多组测试数据. 每组数据有一个方程 a*x1^2 + b*x2^2 + c*x3^2 + d*x4^2 = 0,方程中四个未知数 x1, x2, x3, x4 ∈ [-100, 100], 且 ...
- ACM Changchun 2015 L . House Building
Have you ever played the video game Minecraft? This game has been one of the world's most popular ga ...
- SpringMVC之Controller简单使用
//环境 spring-4.3.18/JDK1.8/开发工具/IntelliJ IDEA 2018.2.5 x64 //工程结构图 //web.xml <?xml version="1 ...
- win7下设置git客户端
msysgit官网: http://msysgit.github.io/ 下载msysgit http://msysgit.googlecode.com/files/Git-1.8.5.2-previ ...
- 匈牙利算法 - Luogu 1963 变换序列
P1963 变换序列 题目描述 对于N个整数0,1,-,N-1,一个变换序列T可以将i变成Ti,其中:Ti∈{0,1,-,N-1}且 {Ti}={0,1,-,N-1}. x,y∈{0,1,-,N-1} ...
- 如何理解redo和undo的作用
目录 如何理解redo和undo的作用 redo undo UNDO和REDO的区别 如何理解redo和undo的作用 redo 重做日志(redo)包含所有数据产生的历史改变记录,是oracle在线 ...
- Eclipse下创建Spring MVC web程序--非maven版
首先, 安装eclipse和tomcat, 这里我下载的是tomcat9.0版本64位免安装的:地址https://tomcat.apache.org/download-90.cgi 免安装的如何启动 ...