可惜没如果=_=
时光的河入海流

1419: Red is good

Time Limit: 10 Sec  Memory Limit: 64 MB
Submit: 1018  Solved: 463
[Submit][Status][Discuss]

Description

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

Input

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

Output

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

Sample Input

5 1

Sample Output

4.166666

HINT

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

Source

哇呀呀呀呀laj没想到用滚动数组存期望=_=

f[i][j]表示选了i个红j个黑

 

 

 1 #include "bits/stdc++.h"
 2 using namespace std;
 3 typedef long long LL;
 4 typedef double D;
 5 const int MAX=5005;
 6 int n,m;
 7 double f[2][MAX];
 8 inline double mx(D x,D y){return x>y?x:y;}
 9 int main(){
10     freopen ("card.in","r",stdin);freopen ("card.out","w",stdout);
11     int i,j;
12     scanf("%d%d",&n,&m);
13     for (i=0;i<=n;i++){
14         f[i%2][0]=i;
15         for (j=1;j<=m;j++){
16             f[i%2][j]=mx( 0.0 , i*1.0/( (i+j)*1.0 )*( f[(i+1)%2][j]+1.0 ) + j*1.0/( (i+j)*1.0 )*( f[i%2][j-1]-1.0 ) );
17         }
18     }
19     LL ans=f[n%2][m]*1e6;
20     printf("%lf",ans*1.0/1e6);
21     return 0;
22 }

 

 

posted on 2017-10-25 14:39  珍珠鸟  阅读(103)  评论(0编辑  收藏  举报