bzoj 1419 Red is good 【期望dp】
来源:互联网 发布:黎明杀机怎么优化fps 编辑:程序博客网 时间:2024/05/21 09:00
Description
桌面上有R张红牌和B张黑牌,随机打乱顺序后放在桌面上,开始一张一张地翻牌,翻到红牌得到1美元,黑牌则付出1美元。可以随时停止翻牌,在最优策略下平均能得到多少钱。
Input
一行输入两个数R,B,其值在0到5000之间
Output
在最优策略下平均能得到多少钱。
Sample Input
5 1
Sample Output
4.166666
HINT
输出答案时,小数点后第六位后的全部去掉,不要四舍五入.
解题思路
关键是考虑什么时候是最优策略。
仔细想了就发现,如果当前期望都不是正数了,那不如不拿,这样当前期望就变为了0,其他情况都可以再拿,这样就可以最优了。
设f[i][j]表示还有i张红牌,j张黑牌的最优期望,那么:
f[i][j]=max(0,
初始化f[i][0]=i;
注意输出,还有要开滚动数组。
#include<iostream>#include<cstdio>#include<cstring>#include<string>#include<algorithm>#include<cmath>#include<vector>#include<queue>#define ll long longusing namespace std;int getint(){ int i=0,f=1;char c; for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar()); if(c=='-')f=-1,c=getchar(); for(;c>='0'&&c<='9';c=getchar())i=(i<<3)+(i<<1)+c-'0'; return i*f;}const int N=5005;int n,m;double f[2][N];int main(){ //freopen("lx.in","r",stdin); n=getint(),m=getint(); int now=1; for(int i=1;i<=n;i++) { f[now][0]=i; for(int j=1;j<=m;j++) f[now][j]=max((double)0,i*1.0/(i+j)*(f[now^1][j]+1)+j*1.0/(i+j)*(f[now][j-1]-1)); now^=1; } now^=1; double ans=floor(f[now][m]*1000000)*1.0/1000000; printf("%0.6f",ans); return 0;}
阅读全文
0 0
- BZOJ 1419 Red is good 期望DP
- BZOJ 1419: Red is good|期望Dp
- bzoj 1419: Red is good 期望dp
- 【BZOJ 1419】Red is good 期望dp
- BZOJ 1419: Red is good 期望DP
- BZOJ 1419: Red is good 期望DP
- bzoj 1419 Red is good 【期望dp】
- bzoj 1419 Red is good 概率dp求期望
- 【bzoj 1419】Red is good(期望DP)
- bzoj 1419: Red is good (概率与期望)
- bzoj 1419 Red is good(概率与期望)
- 1419: Red is good 概率与期望 DP
- 【bzoj1419】Red is good 期望dp
- [bzoj1419]Red is good 期望DP
- 【BZOJ1419】Red is good 期望DP
- BZOJ1419:Red is good(期望DP)
- 【BZOJ1419】【期望DP】Red is good 题解
- 【期望DP】BZOJ1419[Red is good]题解
- transformDexArchiveWithExternalLibsDexMergerForDebug unable to merge dex 问题
- System.arraycopy()方法详解
- XILINK SDK怎么使用自带串口终端
- SpringMVC默认单例的,高并发情况下,如何保证性能的?
- json序列化ipaddress类
- bzoj 1419 Red is good 【期望dp】
- 【bzoj1131】[POI2008]Sta
- numeric(30,0);大数字,用的最大的数字
- 简洁搭建hadoop伪分布式文件系统
- C盘文件移动方法
- Spark性能调优之数据倾斜调优
- 总结:MYSQL5.7.19免安装版 安装配置+修改密码的方法
- 遍历treeview下所有的节点,包括子节点,以勾选为例
- java总结