HDU4405 Aeroplane chess(期望dp)

时间:2022-12-03 15:38:41

题意

抄袭自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 + , INF = 1e9 + ;
const double eps = 1e-;
inline int read() {
char c = getchar(); int x = , f = ;
while(c < '' || c > '') {if(c == '-') f = -; c = getchar();}
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x * f;
}
int N, M, to[MAXN];
double f[MAXN];
int main() {
while(scanf("%d %d", &N, &M)) {
if((N == ) && (M == )) break;
memset(to, , sizeof(to));
memset(f, , sizeof(f));
for(int i = ; i <= M; i++) {
int x = read(), y = read();
to[x] = y;
}
for(int x = N - ; x >= ; x--) {
if(to[x]) f[x] = f[to[x]];
else {
for(int j = ; j <= ; j++) f[x] += f[x + j];
f[x] /= ; f[x]++;
}
}
printf("%.4lf\n", f[]);
}
return ;
}
/* */