题意:

n+1格飞行棋,编号0-n,从0格开始,每次扔一个色子,得到的点数就向前走几步,但有有些格子到达后可以直接飞到后面的格子,

当到达>=n的地方结束,求结束扔色子的期望次数。

分析:

dp[i]表示i格到结束需要的期望次数,dp[n]-dp[n+5]是0,dp[0]即为所求,先处理直接飞的情况

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define N 100010
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
double dp[N];
//fly[i]i格可以最终飞到的格子
int fly[N],n,m;
void solve(){
memset(dp,,sizeof(dp));
for(int i=n-;i>=;--i){
if(fly[i]!=-){
dp[i]=dp[fly[i]];//可由前面的格子飞过来
}
else{
//6种情况
for(int j=;j<=;++j)
dp[i]+=dp[i+j]/6.0;
dp[i]+=1.0;
}
}
printf("%.4lf\n",dp[]);
}
int main()
{
while(~scanf("%d%d",&n,&m)){
if(n==&&m==)break;
memset(fly,-,sizeof(fly));
int u,v;
while(m--){
scanf("%d%d",&u,&v);
fly[u]=v;
}
for(int i=;i<=n;++i){
int j=fly[i];
if(j==-)continue;
while(fly[j]!=-){
j=fly[j];
}
fly[i]=j;
}
solve();
}
return ;
}

HDU 4405-Aeroplane chess(概率dp)的更多相关文章

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

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

  2. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  3. HDU 4405 Aeroplane chess 概率DP 难度:0

    http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能 ...

  4. HDU 4405 Aeroplane chess(概率dp,数学期望)

    题目 http://kicd.blog.163.com/blog/static/126961911200910168335852/ 根据里面的例子,就可以很简单的写出来了,虽然我现在还是不是很理解为什 ...

  5. HDU 4405 Aeroplane chess 期望dp

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

  6. hdu 4405 Aeroplane chess (概率DP)

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

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

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

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

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

  9. 【刷题】HDU 4405 Aeroplane chess

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

  10. HDU 4405 Aeroplane chess (概率DP求期望)

    题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...

随机推荐

  1. SDUT1466双向队列

    http://acm.sdut.edu.cn/sdutoj/showproblem.php?pid=1466&cid=1182 题目描述 想想双向链表……双向队列的定义差不多,也就是说一个队列 ...

  2. IE插件DebugBar如何安装及使用

    DebugBar插件是一款功能很强大的IE插件,用户可以从各个不同的角度剖析Web页面内部,包括页面 详细代码.CSS样式表.所有链接.所有图片代码.脚本信息等等,不管你是编程大虾还是IT新人都和适合 ...

  3. lintcode:最大子数组II

    题目 最大子数组 II 给定一个整数数组,找出两个不重叠子数组使得它们的和最大. 每个子数组的数字在数组中的位置应该是连续的. 返回最大的和. 样例 给出数组[1, 3, -1, 2, -1, 2], ...

  4. *[hackerrank]Consecutive Subsequences

    https://www.hackerrank.com/contests/w6/challenges/consecutive-subsequences 求数组中被k整除的子段和有几个.这个要利用sum[ ...

  5. css一个图片包含多个图片|网站侧栏导航

    <html> <head><title>Hello World</title> <style> .style1{ width:60px;ma ...

  6. React-Flux 介绍及实例演示

    一.Flux架构 二.例子 1.TodoApp.react.js /** * Copyright (c) 2014-2015, Facebook, Inc. * All rights reserved ...

  7. 不重启使XP环境变量生效

    不重启使XP环境变量生效 http://www.pkghost.cn/wz/sort0185/8874.html 在“我的电脑”->“属性”->“高级”->“环境变量”中增加或修改环 ...

  8. 关于矩阵最通俗的解释-超级经典zz

    线性代数课程,无论你从行列式入手还是直接从矩阵入手,从一开始就充斥着莫名其妙.比如说,在全国一般工科院系教学中应用最广泛的同济线性代数教材(现在到了第四版),一上来就介绍逆序数这个“前无古人,后无来者 ...

  9. 23.allegro中自动布线[原创]

    1. --- 方法①:选择网络自动布线 -- --- 已经步好: --- 方法②: ---- ---- 布线: --- 方法③: -- ----

  10. UVa 699 The Falling Leaves

    题意:给出按先序输入的一颗二叉树,分别求出从左到右的相同横坐标上的节点的权值之和 递归建树,然后用sum数组分别统计每一个横坐标上的权值之和 感觉建树都在递归递归递归= =慢慢理解吧 #include ...