HDU 4405 Aeroplane chess (概率DP求期望)
2014-07-09 16:31
513 查看
题意:有一个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];
其中有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> #include<string.h> #include<string> #include<map> #include<stack> #include<math.h> #include<queue> #include<vector> #include<stdlib.h> #include<iostream> #include<algorithm> using namespace std; #define maxn 100000 map<int,int> mp; int main() { int n,m; double dp[maxn]; while(scanf("%d%d",&n,&m)) { if(n==0&&m==0) break; int a,b; for(int i=0;i<=n;i++) mp[i]=-1; while(m--) { scanf("%d%d",&a,&b); mp[a]=b; } memset(dp,0.0,sizeof(dp)); for(int i=n-1;i>=0;i--) { if(mp[i]!=-1) dp[i]=dp[mp[i]]; else { for(int j=1;j<=6;j++) dp[i]+=dp[i+j]; dp[i]=dp[i]/6+1; } } printf("%.4lf\n",dp[0]); } return 0; } /* 2 0 8 3 2 4 4 5 7 8 0 0 */
相关文章推荐
- hdu 4405 Aeroplane chess (概率DP+求期望)
- HDU 4405 Aeroplane chess (概率DP求期望)
- hdu 4405 Aeroplane chess(简单概率dp 求期望)
- HDU 4405 Aeroplane chess 概率dp求期望
- HDU-4405 Aeroplane chess(概率DP求期望)
- HDU 4405 Aeroplane chess(概率dp,数学期望)
- 简单概率dp(期望)-hdu-4405-Aeroplane chess
- HDU 4405 - Aeroplane chess (概率DP 求期望)
- HDU 4405 Aeroplane chess(概率DP求期望)
- HDU 4405 Aeroplane chess(概率DP求期望)
- hdu 4405 Aeroplane chess(概率DP 求期望__附求期望讲解方法)
- HDU 4405 Aeroplane chess (概率-期望DP)【模板】
- HDU 4405 Aeroplane chess (概率DP & 期望)
- HDU 4405 Aeroplane chess(全期望公式-概率dp)
- hdu 4405 Aeroplane chess 2012年金华区域赛网络赛 概率dp求期望
- hdu 4405 Aeroplane chess【概率DP求期望】
- [hdu 4405] Aeroplane chess [概率DP & 期望]
- HDU 4405 Aeroplane chess(概率DP求期望)
- hdu 4405 Aeroplane chess 概率dp
- 【解题报告】 HDU 4405 Aeroplane chess - 递推概率问题,从后往前推算即可得到期望