codeforces 148D Bag of mice(概率dp)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完之后会随机跳出来一个。取到每个小鼠的概率是一样的,跳出的也是一样的。先取到白色的小鼠赢,问最后princess能赢的概率。
思路:概率dp,如果把princess能赢的分成两种情况,那么这个题就是递推了,我是用记忆化搜索写的。首先,用dp[i][j]表示袋子当中还有i个白色的,j个黑色的princess能取赢的概率。那么有两种情况:
1.这一步能取赢,那么就是直接取到白色的,概率为i/(i+j);
2.这一步取不赢,那么当前一定是取到黑色的,因为最后要让princess赢,所以,接着dragon也取不赢,现在还有一个问题是,跳出的小鼠的颜色,那么又分为两种情况:
1). 跳出的为白色的。概率就是j/(i+j)*(j-1)/(i+j-1)*(i)/(i+j-2)*dp[i-1][j-2]
2). 跳出的位黑色的。概率就是j/(i+j)*(j-1)/(i+j-1)*(j-2)/(i+j-2)*dp[i][j-3]
推到这里基本上就出来了,剩下的边界条件了。如果i==0,那么概率一定是0, 如果i>0&&j==0那么概率一定为1.
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std; const int maxn = ;
double dp[maxn][maxn];
double dfs(int i, int j)
{
if (i <= || j < ) return ;
if (i > && j == ) return dp[i][] = ;
if (dp[i][j] != -) return dp[i][j];
double t1 = (double)i / (i + j);
double t2 = (double)j / (i + j);
dp[i][j] = t1;
if (i + j > )
{
double t3 = dfs(i, j - ) * (j - ) / (i + j - ) * (j - ) / (i + j - );
double t4 = dfs(i - , j - ) * (j - ) / (i + j - ) * (i) / (i + j - );
t2 *= (t3 + t4);
dp[i][j] = t1 + t2;
}
return dp[i][j];
}
int main()
{
int w, b;
scanf("%d%d", &w, &b);
//memset(dp, -1, sizeof(dp));
for (int i = ; i <= w; i++)
for (int j = ; j <= b; j++)
dp[i][j] = -;
printf("%.9f\n", dfs(w, b)); return ;
}
codeforces 148D Bag of mice(概率dp)的更多相关文章
- Codeforces 148D Bag of mice 概率dp(水
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
- CF 148D Bag of mice 概率dp 难度:0
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- codeforce 148D. Bag of mice[概率dp]
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 抓老鼠 codeForce 148D - Bag of mice 概率DP
设dp[i][j]为有白老鼠i只,黑老鼠j只时轮到公主取时,公主赢的概率. 那么当i = 0 时,为0 当j = 0时,为1 公主可直接取出白老鼠一只赢的概率为i/(i+j) 公主取出了黑老鼠,龙必然 ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- Codeforces Round #105 (Div. 2) D. Bag of mice 概率dp
题目链接: http://codeforces.com/problemset/problem/148/D D. Bag of mice time limit per test2 secondsmemo ...
- Bag of mice(概率DP)
Bag of mice CodeForces - 148D The dragon and the princess are arguing about what to do on the New Y ...
- CF 148D. Bag of mice (可能性DP)
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- Codeforces 148D Bag of mice:概率dp 记忆化搜索
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公 ...
随机推荐
- USB数据线上的“疙瘩”:原来有这么大用处!
在不少键盘.鼠标或是游戏外设的数据线末端我们都能见到一小段金属圆环.虽然这算得上是习以为常的一个设计,但如果说到其具体作用的话很多人一下子还真回答不上来.反正笔者在这里先可以告诉大家,这货肯定不是简简 ...
- 【Xamarin挖墙脚系列:应用的性能调优】
原文:[Xamarin挖墙脚系列:应用的性能调优] 官方提供的工具:网盘地址:http://pan.baidu.com/s/1pKgrsrp 官方下载地址:https://download.xamar ...
- Android Animation初识
3.0以前,android支持两种动画模式,tween animation,frame animation,在android3.0中又引入了一个新的动画系统:property animation,这三 ...
- 关于v$sql_bind_capture 的问题
---先清空shared_pool SQL> alter system flush shared_pool; System altered. SQL> col value_STRING f ...
- gunicorn启动报错gunicorn.errors.HaltServer
启动gunicorn报错: # gunicorn -b :9008 -w 2 webserver:app 2013-12-10 09:12:58 [29701] [INFO] Starting gun ...
- 嵌套滚动demo
https://github.com/luv135/NestedScrollingDemo https://github.com/ggajews/nestedscrollingchildviewdem ...
- C#设计模式(23种设计模式)
转自:http://www.cnblogs.com/abcdwxc/archive/2007/10/30/942834.html 创建型: 1. 单件模式(Singleton Patte ...
- [PeterDLax著泛函分析习题参考解答]第3章 Hahn-Banach 定理
1. 证明 $(10'$). 证明: $\ra$: 由 $p_K(x)<1$ 知 $$\bex \exists\ 0<a<1,\st \cfrac{x}{a}\in K. \eex$ ...
- Toad for Oracle 使用文档
Toad®for Oracle 版本 12.0.1 发行说明 30 July 2013 目录 欢迎使用 Toad for Oracle 版本更新 解决的问题和改进 已知问题 第三方已知问题 升级和兼容 ...
- php--常用的时间处理函数
天地四方曰宇,往古来今曰宙 时间是世界的重要组成部分,不论花开花落,还是云卷云舒都有它的影子. 但它源起何处?又将去向何方?没人知道答案,也不需要答案,我们需要的只是一个相对的起点来标识时间,现今世界 ...