Description

桌面上有R张红牌和B张黑牌,随机打乱顺序后放在桌面上,开始一张一张地翻牌,翻到红牌得到1美元,黑牌则付出1美元。可以随时停止翻牌,在最优策略下平均能得到多少钱。

Input

一行输入两个数R,B,其值在0到5000之间

Output

在最优策略下平均能得到多少钱。

Sample Input

5 1

Sample Output

4.166666

HINT

输出答案时,小数点后第六位后的全部去掉,不要四舍五入.

题解:用f[i][j]表示还剩i张红牌,j张黑牌,期望得到的钱数是多少。那么如果期望为正则抽牌,否则不抽。

#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
double f[2][5010];
int n,m;
int main()
{
	scanf("%d%d",&n,&m);
	int i,j;
	for(i=0;i<=n;i++)
	{
		for(j=0;j<=m;j++)
		{
			f[i&1][j]=max(0.0,((!i?0:f[(i&1)^1][j]+1)*i/(i+j))+(!j?0:(f[i&1][j-1]-1)*j/(i+j)));
		}
	}
	printf("%.6lf",f[n&1][m]-0.0000005);
	return 0;
}

相关文章:

  • 2021-10-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2022-01-01
  • 2022-01-30
  • 2021-07-13
猜你喜欢
  • 2021-09-01
  • 2021-08-22
  • 2021-09-30
  • 2021-07-26
  • 2022-01-10
  • 2021-07-10
  • 2021-07-05
相关资源
相似解决方案