类型:概率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的更多相关文章

  1. HDU 4405:Aeroplane chess(概率DP入门)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Problem Description   Hzz loves ...

  2. 【HDOJ】【4405】Aeroplane chess飞行棋

    概率DP/数学期望 kuangbin总结中的第4题 啊还是求期望嘛……(话说Aeroplane chess这个翻译怎么有种chinglish的赶脚……) 好像有点感觉了…… 首先不考虑直飞的情况: f ...

  3. hdu4405:Aeroplane chess

    题目大意:有编号为0-n的格子,从0开始,扔骰子扔到几就走几格.有m个瞬移点,每个点可以从格x直接飞到格y,若瞬移到另一个瞬移点可以继续瞬移.求到达格n的期望扔骰子次数. 题解:期望DP入门好题.网上 ...

  4. HDU 4405 Aeroplane chess 期望dp

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

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

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

  6. hdu 4405 Aeroplane chess (概率DP)

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

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

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

  8. Aeroplane chess(HDU 4405)

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

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

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

随机推荐

  1. 洛谷 P5015 标题统计

    第一道题很简单,标签:字符串.模拟. 只需要一个判断去除空格就对了: if(a[i]!=' ' && a[i]!='\n') v++; code: #include<iostre ...

  2. 【思维题 费用流 技巧】bzoj5403: marshland

    主要还是网络流拆点建图一类技巧吧 Description JudgeOnline/upload/201806/1(4).pdf 题目分析 第一眼看到这题时候只会把每个点拆成4个方向:再强制定向连边防止 ...

  3. 初涉manacher

    一直没有打过……那么今天来找几道题打一打吧 manacher有什么用 字符串的题有一类是专门关于“回文”的.通常来说,这类问题要么和一些dp结合在一起:要么是考察对于manacher(或其他如回文自动 ...

  4. 一个form表单对应多个submit

    一个form表单多个submit 在平时项目开发过程中,经常会遇到一个form表单对应多个submit提交的情况,那么 ,这种情况应该怎么解决呢,也很简单,这时候就不能用submit来提交了,可以通过 ...

  5. Java-basic-4-数据类型

    Number类 装箱:将内置数据类型作为包装类对象使用:拆箱:相反 public class test{ public static void main(String args[]) { // box ...

  6. IAR生成bin,HEX文件

    1.生成bin,hex文件 options->output converter->output format binary:.bin文件:intel extended:hex文件. 生成的 ...

  7. BZOJ 4425: [Nwerc2015]Assigning Workstations分配工作站

    难度在于读题 #include<cstdio> #include<algorithm> #include<queue> using namespace std; p ...

  8. virtual 三种用法

    virtual用法一 #include using namespace std;class A{public:     virtual  void  display(){  cout<<& ...

  9. luogu3371 【模板】单源最短路径 dijkstra堆优化

    #include <algorithm> #include <iostream> #include <cstring> #include <cstdio> ...

  10. 常见的Linux目录及其含义

    /                                   系统根目录,通常不会在这里存放文件 . /bin                              二进制目录,存放许多 ...