BZOJ 1419: Red is good 期望dp
数学期望可以理解成一个 DAG 模型.
Code:
#include <bits/stdc++.h> #define N 5003 #define ll long long #define setIO(s) freopen(s".in","r",stdin) using namespace std; int n,m; double f[3][N]; int main() { int i,j; // setIO("input"); scanf("%d%d",&n,&m); int now=0; for(i=1;i<=n;++i,now^=1) { f[now][0]=i; for(j=1;j<=m;++j) { f[now][j]=max(0.0,1.0*i/(i+j)*(1+f[now^1][j])+1.0*j/(i+j)*(-1+f[now][j-1])); } } ll x=1000000*f[now^1][m]; printf("%.6lf\n",1.0*x/1000000); return 0; }