终于还是面对这道题了,考试的时候没学期望,现在看来其实挺简单的。当时跑了个暴力,然后不知道加了些什么优化,居然跑了80分出来。
Floyd部分就不说了,只是算一下每2个教室间的距离而已,重点在期望。
期望我们设f(i,j,0)为前i个教室申请了j次第i个教室没申请的情况的数学期望。
相对的f(i,j,1)为前i个教室申请了j次第i个教室申请了的情况的数学期望。
下面就是转移了,我们可以证明到前面的情况出来第i-1次是否申请都与i无关,所以转移方程就出来了。
详细的解释我在代码里注释了,代码如下:
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int maxn=2005;
int a[maxn][2],n,m,v,e;
double d[305][305],c[maxn];
double f[maxn][maxn][2];