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 #include<queue>
 6 #include<stack>
 7 #include<algorithm>
 8 #include<cstring>
 9 #include<stdlib.h>
10 using namespace std;
11 #define pb push_back
12 struct node{
13     int x,y;
14 }p[1010];
15 int cmp(node a,node b){
16     return a.x<b.x;
17 }
18 int main()
19 {
20     int n,m;
21     while(cin>>n>>m,n+m){
22         double dp[101010];
23         memset(dp,0,sizeof(dp));
24         for(int i=0;i<m;i++)
25             scanf("%d%d",&p[i].x,&p[i].y);
26         sort(p,p+m,cmp);
27         int cnt=m-1;
28         for(int i=n-1;i>=0;i--){
29               dp[i]=1;
30               if(cnt>=0&&i==p[cnt].x){
31                dp[i]=dp[p[cnt].y];
32                cnt--;
33                continue;
34               }
35               for(int j=6;j>=1;j--)
36                 dp[i]+=1.0/6*dp[i+j];
37         }
38         printf("%.4f\n",dp[0]);
39     }
40 }

hdu 4405 Aeroplane chess,布布扣,bubuko.com

时间: 2024-10-21 19:21:23

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>

[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入门题

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+求期望)

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)

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

hdu 4405 Aeroplane chess 动态规划

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4405 所谓概率DP大多是算期望 算期望大多是从终点往回推 简单的1维动态规划 dp[i]表示第i格到终点的期望步数 从终点往前推 若当前为某条捷径的起点 那么该点的dp值直接等于捷径终点的dp值 否则枚举掷出1到6时所到的位置的期望 用最朴素的方法求期望 dp[0]即为所求 #include <cstdio> #include <cstdlib> #include <ctime&