hdu 4405 Aeroplane chess(期望)

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

有n+1个点,0~n ,某人现在站在x处,若x处有flight lines,他就能飞到相应点而不用掷骰子,否则就向前走掷出的骰子上的数字。问他从0点到达n点需要投掷骰子的平均次数。

还是一样的题型,已知dp[n] = 0,然后根据当前点能到达的下一点的概率进行逆推。dp[0]就是答案。

#include <stdio.h>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <vector>
#include <math.h>
#include <string.h>
#include <queue>
#include <string>
#include <stdlib.h>
#include <algorithm>
//#define LL __int64
#define LL long long
#define eps 1e-9
#define PI acos(-1.0)
using namespace std;
const int INF = 0x3f3f3f3f;
const int maxn = 4010;

double dp[100010];
int hash[100010];

int main()
{
    int n,m,u,v;
    while(~scanf("%d %d",&n,&m))
    {
        if(n == 0 && m == 0)
            break;
        memset(dp,0,sizeof(dp));
        memset(hash,-1,sizeof(hash));
        while(m--)
        {
            scanf("%d %d",&u,&v);
            hash[u] = v;
        }
        for(int i = n; i >= 0; i--)
        {
            if(i == n) continue;
			if(hash[i] == -1)
            {
            	for(int j = i+1; j <= i+6; j++)
						dp[i] += dp[j];
				dp[i] /= 6;
				dp[i] += 1;
            }
			else
				dp[i] = dp[hash[i]];
        }
        printf("%.4lf\n",dp[0]);
    }
    return 0;
}
时间: 2024-11-14 15:56:19

hdu 4405 Aeroplane chess(期望)的相关文章

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

题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点需要步数的期望 其中有m个跳跃a,b表示走到a点可以直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点可以到走到i+1,i+2,i+3,i+4,i+5,i+6 点且每个点的概率都为1/6 所以dp[i]=(dp[i+1]+dp[i+2]+dp[i+3]+dp[i+4]+dp[i+5]+dp[i+6])/6  + 1(步数加一). 而对于有跳跃的点直接为dp[a]=dp[b]; #include<stdio.h>

hdu 4405 Aeroplane chess

题意: hzz一开始在0位置,然后hzz掷骰子,骰子为i,就往前走i步,当hzz位置大于等于n的时候结束,求掷骰子次数的期望 有m个直达点 (x,y),走到x时可以直接到y 求期望一般从后往前推 当 i不等于任何一个x时 dp[i]=seg(1/6*dp[i+k])+1 否则 dp[i]=dp[y] 1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5

[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 求期望__附求期望讲解方法)

题目链接: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

hdu 4405 Aeroplane chess (概率DP+求期望)

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1551    Accepted Submission(s): 1063 Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids labeled from 0 to

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): 1503    Accepted Submission(s): 1025 Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids la

hdu 4405 Aeroplane chess(概率+dp)

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 numbers on the faces a

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