求期望值,体重说明,如果可以flight的话就直接到达规定那个点,用f数组将两个点连在一起就可以,反之,就要求打骰子后的期望啦,e[i] = ∑(e[i + k] * 1 / 6) + 1(k为点数1~6,1/6为致筛子的概率,因为不可以flight就要置一次筛子,所以+1)。
/*************************************************************************
> File Name: hdoj4405.cpp
> Author: AcToy
> Mail: ycsgldy@163.com
> Created Time: 2013年07月17日 星期三 09时19分05秒
************************************************************************/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <climits>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef unsigned int u32;
typedef long long i64;
typedef unsigned long long u64;
typedef vector<int> IV;
typedef vector<bool> BV;
typedef pair<int,int> II;
typedef vector<II> IIV;
#define For(t,v,c) for(t::const_iterator v=c.begin(); v!=c.end(); ++v)
const int INF = 0x7FFFFFFF;
const double eps = 1E-10;
const double PI = acos(-1);
const int maxn = 100000;
double e[maxn];
int f[maxn], n, m;
int main () {
while(scanf("%d%d", &n, &m) == 2 && n) {
memset(f, 0, sizeof(f));
for(int i = 0; i <= n; e[i] = 0, ++i) ;
for(int i = 1; i <= m; ++i) {
int x, y;
scanf("%d%d", &x, &y);
f[x] = y;
}
for(int i = n - 1; i >= 0; --i) {
if(f[i]) e[i] = e[f[i]];
else {
for(int j = 1; j <= 6; ++j) {
if(i + j <= n) e[i] += e[i + j] * 1.0 / 6;
else break;
}
e[i] += 1.0;
}
}
printf("%.4lf\n", e[0]);
}
return 0;
}