HDU 4405:Aeroplane chess 概率DP求期望

One Person Game

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=4405

题意:

有个人在玩飞行棋,规则是:掷一个骰子,就能从当前点x飞到(x+点数)处,在棋盘上有一些飞行通道,如果点x和点y间存在飞行通道,那么当你走到点x,就会飞到点y处,起点在0,求从起点飞到终点n所需要投掷骰子次数的期望。

题解:

一道简单的求期望的题,不会求期望的可以看下这里

当点i是飞行通道的起点的时候,由于不需要投掷骰子,就能飞到飞行通道的终点处,所以此时dp[i]=dp[飞行通道的终点]

当点i不是是飞行通道的起点的时候,在掷一次骰子后可以飞到i+点数处,所以此时dp[i]=∑dp[i+k]*1/6 +1

             

代码

#include<stdio.h>
#include<string.h>
using namespace std;
const int N=100005;
double dp[N];
int q[N];
int main()
{
  int n,m,x,y;
  while(~scanf("%d%d",&n,&m)&&(n||m))
  {
    memset(q,0,sizeof(q)); 
    memset(dp,0,sizeof(dp));
    while(m--)
    {
      scanf("%d%d",&x,&y);
      q[x]=y;
    }
    for(int i=n-1;i>=0;--i)
    if(!q[i])
    {
      for(int j=1;j<=6;++j)
      if(i+j<=n) dp[i]+=dp[i+j]/6.0;
      dp[i]++;
    }
    else dp[i]=dp[q[i]];
    printf("%.4f\n",dp[0]);
  }
}

  

时间: 2024-08-05 09:45:24

HDU 4405:Aeroplane chess 概率DP求期望的相关文章

hdu 4405 Aeroplane chess(概率DP 求期望__附求期望讲解方法)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal p

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

Aeroplane chess Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the number

hdu 4405 Aeroplane chess 概率dp入门题

Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to N. Hzz starts at grid 0. For each step he throws a dice(a dice have six faces with equal probability to face up and the numbers on the faces are 1,2,3

HDU 4405 Aeroplane chess 概率DP 水题

Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2327    Accepted Submission(s): 1512 Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids lab

HDU 4405 Aeroplane chess (概率DP &amp; 期望)

题目的意思是有n个格子,掷色子的掷出的数目就是你一次到移动格数.其中有m个飞行通道可以让你直接从第xi格飞到第yi格.问你走到终点的期望是多少. http://www.cnblogs.com/jackge/archive/2013/05/21/3091924.html 期望求解步骤理解 :http://kicd.blog.163.com/blog/static/126961911200910168335852/ #include<iostream> #include<cstdio>

HDU 4405 Aeroplane chess 概率DP 难度:0

http://acm.hdu.edu.cn/showproblem.php?pid=4405 明显,有飞机的时候不需要考虑骰子,一定是乘飞机更优 设E[i]为分数为i时还需要走的步数期望,j为某个可能投出的点数如果从i向i-j推导,我们并不能确定i的转移方向,因为可能有两个i-j有飞机其目的地是i,所以我们选择从i向i+j推导期望 如果设G[i]为分数为i时已经走过的步数期望,那么要确定G[i+j]需要知道P(i|i+j),也即转移到i+j的条件下从i转移来的概率,比较麻烦 由题意,设match

HDU 4405 Aeroplane chess 概率dp

题目大意: 跳棋有0~n个格子,每个格子X可以摇一次色子,色子有六面p(1=<p<=6),概率相等,可以走到X+p的位置,有些格子不需要摇色子就可以直接飞过去.问从0出发到达n或超过n摇色子的次数的期望. (copy的 思路: 先处理一下每个点最远能飞到的点 保证只会往终点的方向飞.. 能确定的状态就是最终n-n+5这6个点的步数是0 然后从后往前递推 #include <cstdio> #include <iostream> #include <cstring&

HDU 4050 wolf5x (概率DP 求期望)

题意:有N个格子,1~N,起点在0,每个格子有一个状态(0,1,2,3),每次可以跨[a,b]步, 问走完N个格子需要步数的期望,每次尽量走小的步数,即尽量走a步,不能则走a+1,-- 状态0意味着你不能踏进对应的网格. 状态1意味着你可以??步入网格用你的左腿. 状态2意味着你可以??步入网格用你的右腿. 状态3意味着你可以进入网格用任何你的腿,而接下来的步骤中,您可以使用任何的腿;即你不需要遵循上述规则. 思路:借鉴了各路大神的思想理解了下. dp[i][j] :表示走到第 i 个格子在 j

HDU 3853 LOOPS(概率dp求期望啊)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help her friend Madoka save the world. But because of the plot of the Boss Incubator, she is trapped in