Bag of mice

The dragon and the princess are arguing about what to do on the New Year's Eve. The dragon suggests flying to the mountains to watch fairies dancing in the moonlight, while the princess thinks they should just go to bed early. They are desperate to come to an amicable agreement, so they decide to leave this up to chance.

They take turns drawing a mouse from a bag which initially contains w white and b black mice. The person who is the first to draw a white mouse wins. After each mouse drawn by the dragon the rest of mice in the bag panic, and one of them jumps out of the bag itself (the princess draws her mice carefully and doesn't scare other mice). Princess draws first. What is the probability of the princess winning?

If there are no more mice in the bag and nobody has drawn a white mouse, the dragon wins. Mice which jump out of the bag themselves are not considered to be drawn (do not define the winner). Once a mouse has left the bag, it never returns to it. Every mouse is drawn from the bag with the same probability as every other one, and every mouse jumps out of the bag with the same probability as every other one.

Input

The only line of input data contains two integers w and b (0 ≤ w, b ≤ 1000).

Output

Output the probability of the princess winning. The answer is considered to be correct if its absolute or relative error does not exceed 10 - 9.

Examples

Input
1 3
Output
0.500000000
Input
5 5
Output
0.658730159

题意:一对情侣玩抓老鼠游戏,老鼠有黑白两色,女生为先手,先抓到白老鼠胜。 特别的,若两人均未抓到则算男生赢,且两人抓完后会跑走一只老鼠,还会随机放走一只老鼠,问女生赢的概率是多少。

解析:

设dp[i][j]表示现在轮到女生抓时有i只白鼠,j只黑鼠,女赢的概率
明显 dp[0][j]=0,0<=j<=b;因为没有白色老鼠了
dp[i][0]=1,1<=i<=w;因为都是白色老鼠,抓一次肯定赢了。
dp[i][j]可以转化成下列四种状态:
1、女生抓到一只白鼠,则女赢了,概率为i/(i+j);
2、女生抓到一只黑鼠,男生抓到一只白色,则女输了,概率为j/(i+j)*i/(i+j-1).
3、女生抓到一只黑鼠,男生抓到一只黑鼠,跑出来一只黑鼠,则转移到dp[i][j-3]。
概率为j/(i+j)*(j-1)/(i+j-1)*(j-2)/(i+j-2);
4、女生抓到一只黑鼠,男生抓到一只黑鼠,跑出来一只白鼠,则转移到dp[i-1][j-2].
概率为j/(i+j)*(j-1)/(i+j-1)*i/(i+j-2); 当然后面两种情况要保证合法,即第三种情况要至少3只黑鼠,第四种情况要至少2只白鼠
*/
代码:
 #include"bits/stdc++.h"

 #define db double
#define ll long long
#define vl vector<ll>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = ;
const db PI = acos(-1.0);
const db eps = 1e-;
const ll INF = 0x3fffffffffffffff; db dp[][];
int t,n,m;
int main()
{
ci(n),ci(m);
for(int i=0;i<=m;i++) dp[][i]=;
for(int i=;i<=n;i++) dp[i][]=;
for(int i=;i<=n;i++){
for(int j=;j<=m;j++)
{
dp[i][j]+=(db)i/(i+j);
if(j>=) dp[i][j]+=(db)j/(i+j)*(db)(j-)/(i+j-)*(db)i/(i+j-)*dp[i-][j-];
if(j>=) dp[i][j]+=(db)j/(i+j)*(db)(j-)/(i+j-)*(db)(j-)/(i+j-)*dp[i][j-];
}
}
printf("%.9f\n",dp[n][m]);
return ;
}

 

最新文章

  1. MySQL备份原理详解
  2. 小众Tox——大众的“去中心化”聊天软件
  3. tet
  4. CSS3 animation 的尝试
  5. nginx后的tomcat获取真实用户ip
  6. getshell工具
  7. Unrecognized Windows Sockets error: 0: JVM_Bind异常
  8. c#泛型方法重载
  9. UART接口
  10. mysql连接的空闲时间超过8小时后 MySQL自动断开该连接解决方案
  11. 弹出框、遮罩层demo
  12. Potato(邪恶土豆)–windows全版本猥琐提权
  13. 菜鸟VUER学习记——零0章、打开新的大门
  14. HDU 3032 Nim or not Nim? [Multi-SG]
  15. intent和手势探测
  16. python 饥饿的小易(网易笔试题)
  17. H5新增元素
  18. 数据特征分析:1.基础分析概述&amp; 分布分析
  19. 【JS】【6】判断一个元素是否在数组中
  20. ldap集成nexus

热门文章

  1. apache安装 windows
  2. mui打包vue项目
  3. bootstrap导航栏的辛酸史
  4. 光标显示样式 css 中 cursor 属性使用
  5. ubuntu16.4安装 VirtualBox
  6. Sublime插件支持Sass编译和Babel解析ES6 &amp; .sublime-build文件初探(转载自imwtr)
  7. 模拟插队,出队,POJ(2259)
  8. P2375 动物园
  9. 统计函数运行时间-CPU端
  10. 共变导数(Covariant Derivative)