[hdu4405]Aeroplane chess

题意:某人掷骰子,数轴上前进相应的步数,会有瞬移的情况,求从0到N所需要的期望投掷次数。

解题关键:期望dp的套路解法,一个状态可以转化为6个状态,则该状态的期望,可以由6个状态转化而来。再加上两个状态的消耗即可。

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 #include<cstdlib>
 5 #include<cmath>
 6 #include<iostream>
 7 using namespace std;
 8 typedef long long ll;
 9 //const int inf=0x3f3f3f3f;
10 const int maxn=1e5+7;
11 int v[maxn];
12 double dp[maxn];
13 int main(){
14     ios::sync_with_stdio(0);
15     int n,m,a,b;
16     while(cin>>n>>m&&(n||m)){
17         memset(dp, 0, sizeof dp);
18         memset(v, 0, sizeof v);
19         for(int i=0;i<m;i++){
20             cin>>a>>b;
21             v[a]=b;
22         }
23         for(int i=n-1;i>=0;i--){
24             if(v[i]){
25                 dp[i]=dp[v[i]];
26                 continue;
27             }
28             for(int j=1;j<=6;j++){
29                 dp[i]+=dp[i+j]/6.0;
30             }
31             dp[i]+=1;
32         }
33         printf("%.4f\n",dp[0]);
34     }
35 }
时间: 2024-10-24 23:15:51

[hdu4405]Aeroplane chess的相关文章

hdu4405——Aeroplane chess

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

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

HDU 4405(Aeroplane chess)

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

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

Aeroplane chess(简单概率dp)

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,4,5,6). Whe

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

http://acm.split.hdu.edu.cn/showproblem.php?pid=4405 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 f

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