HDU-4405 Aeroplane chess 期望DP
2012-09-22 21:14
369 查看
dp[i]表示第i个位置跳出去的期望天数,先构造出N+1到N+5这几个位置,然后先把dp[N-N+5]这六个位置全部赋值为0,因为这几个位置都已经出去了。
然后就是递推了
如果该点没有航班的话:
dp[x] = (1/6)*(dp[x+1] + dp[x+2] + dp[x+3] + dp[x+4] + dp[x+5] + dp[x+6]) + 1;
否则:
dp[x] = dp[link[x]]; 其中link[x]表示x连到哪一个点。
代码如下:
然后就是递推了
如果该点没有航班的话:
dp[x] = (1/6)*(dp[x+1] + dp[x+2] + dp[x+3] + dp[x+4] + dp[x+5] + dp[x+6]) + 1;
否则:
dp[x] = dp[link[x]]; 其中link[x]表示x连到哪一个点。
代码如下:
#include<iostream> #include<cstdio> #include<cstdlib> #include<algorithm> #include<cmath> #include<queue> #include<set> #include<map> #include<cstring> #include<vector> #include<string> #define MAXN 100020 #define LL long long using namespace std; int N, M; const double EE = 1.0/6; double dp[MAXN]; int link[MAXN]; int main( ) { int len, a, b; while (scanf("%d %d", &N, &M) == 2) { len = N+5; memset(link, 0xff, sizeof (link)); for (int i = N; i <= len; ++i) dp[i] = 0; for (int i = 1; i <= M; ++i) { scanf("%d %d", &a, &b); link[a] = b; } for (int i = N-1; i >= 0; --i) { double temp = 0.0; if (link[i] != -1) { temp = dp[link[i]]; } else { for (int j = i + 1; j <= i + 6; ++j) { temp += EE * dp[j]; } temp += 1; } dp[i] = temp; } printf("%.4lf\n", dp[0]); } return 0; }
相关文章推荐
- 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(简单概率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(12年金华网络赛-F题-期望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