首页 > 代码库 > BZOJ 1419 Red is good 期望DP

BZOJ 1419 Red is good 期望DP

题目大意:有R张红牌和B张黑牌打乱扣在桌子上,一张一张翻,可以随时停止翻牌,翻到红牌收益+1,翻到黑牌收益-1,求最优策略下的最大期望收益

OTZ wfycyx= =  http://wyfcyx.is-programmer.com/posts/74629.html

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define M 5050
using namespace std;
int r,b;
double f[2][M];
int main()
{
	int i,j;
	cin>>r>>b;
	for(i=0;i<=r;i++)
		for(j=0;j<=b;j++)
		{
			if(!i) f[i&1][j]=0;
			else if(!j) f[i&1][j]=i;
			else f[i&1][j]=max(0.0,(double)i/(i+j)*(f[~i&1][j]+1)+(double)j/(i+j)*(f[i&1][j-1]-1));
		}
	printf("%.6lf\n",f[r&1][b]-5e-7);
	return 0;
}


BZOJ 1419 Red is good 期望DP