码迷,mamicode.com
首页 > 其他好文 > 详细

HDU4405 Aeroplane chess(期望dp)

时间:2018-08-24 10:52:37      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:clu   chess   比较   lock   mem   main   double   pair   const   

题意

抄袭自https://www.cnblogs.com/Paul-Guderian/p/7624039.html

正在玩飞行棋。输入n,m表示飞行棋有n个格子,有m个飞行点,然后输入m对u,v表示u点可以直接飞向v点,即u为飞行点。如果格子不是飞行点,扔骰子(1~6等概率)前进。否则直接飞到目标点。每个格子是唯一的飞行起点,但不是唯一的飞行终点。问到达或越过终点的扔骰子期望数。

从0出发!!

Sol

比较zz的期望dp

设$f[i]$表示从$i$出发,到达$n$的期望步数

转移的时候讨论一下即可

/*

*/
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<cmath>
#define Pair pair<int, int>
#define MP(x, y) make_pair(x, y)
#define fi first
#define se second
//#define int long long 
//#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1<<22, stdin), p1 == p2) ? EOF : *p1++)
//char buf[(1 << 22)], *p1 = buf, *p2 = buf;
using namespace std;
const int MAXN = 1e5 + 10, INF = 1e9 + 10;
const double eps = 1e-10;
inline int read() {
    char c = getchar(); int x = 0, f = 1;
    while(c < 0 || c > 9) {if(c == -) f = -1; c = getchar();}
    while(c >= 0 && c <= 9) x = x * 10 + c - 0, c = getchar();
    return x * f;
}
int N, M, to[MAXN];
double f[MAXN];
int main() {
    while(scanf("%d %d", &N, &M)) {
        if((N == 0) && (M == 0)) break;
        memset(to, 0, sizeof(to));
        memset(f, 0, sizeof(f));
        for(int i = 1; i <= M; i++) {
            int x = read(), y = read();
            to[x] = y;
        }
        for(int x = N - 1; x >= 0; x--) {
            if(to[x]) f[x] = f[to[x]];
            else {
                for(int j = 1; j <= 6; j++) f[x] += f[x + j];
                f[x] /= 6; f[x]++;
            }
        }
        printf("%.4lf\n", f[0]);
    }
    return 0;
}
/*

*/

HDU4405 Aeroplane chess(期望dp)

标签:clu   chess   比较   lock   mem   main   double   pair   const   

原文地址:https://www.cnblogs.com/zwfymqz/p/9527783.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!