http://codeforces.com/problemset/problem/148/D

题目大意:

  原来袋子里有w只白鼠和b只黑鼠

  龙和王妃轮流从袋子里抓老鼠。谁先抓到白色老鼠谁就赢。

  王妃每次抓一只老鼠,龙每次抓完一只老鼠之后会有一只老鼠跑出来。

  每次抓老鼠和跑出来的老鼠都是随机的。

  如果两个人都没有抓到白色老鼠则龙赢。王妃先抓。

  问王妃赢的概率。

(0 ≤ w, b ≤ 1000).

题解:

  

  其中第一行表示为王妃拿到的白色老鼠,自然是直接退出了

  第二行表示为王妃拿到了黑色老鼠,但是因为不能让龙赢,所以龙必须要抓到黑色老鼠

  那么就应该讨论龙抓完后跑出来的是黑色老鼠还是白色老鼠

  即为对应的2、3两行

 #include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
inline void read(int &x){
x=;char ch;bool flag = false;
while(ch=getchar(),ch<'!');if(ch == '-') ch=getchar(),flag = true;
while(x=*x+ch-'',ch=getchar(),ch>'!');if(flag) x=-x;
}
inline int cat_max(const int &a,const int &b){return a>b ? a:b;}
inline int cat_min(const int &a,const int &b){return a<b ? a:b;}
const int maxn = ;
double f[maxn][maxn];
int main(){
int n,m;read(n);read(m);
for(int i=;i<=n;++i) f[i][] = 1.0;
for(int i=;i<=m;++i) f[][i] = 0.0;
for(int i=;i<=n;++i){
for(int j=;j<=m;++j){
f[i][j] = (double)i/(i+j);
if(j->=) f[i][j] += (double)j/(i+j)*(j-)/(i+j-)*(j-)/(i+j-)*f[i][j-];
if(j->=) f[i][j] += (double)j/(i+j)*(j-)/(i+j-)*i/(i+j-)*f[i-][j-];
}
}printf("%.9lf\n",f[n][m]);
getchar();getchar();
return ;
}

CodeForces - 148D Bag of mice的更多相关文章

  1. Codeforces 148D Bag of mice:概率dp 记忆化搜索

    题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公 ...

  2. Codeforces 148D Bag of mice 概率dp(水

    题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...

  3. codeforces 148D Bag of mice(概率dp)

    题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. CF 148D Bag of mice【概率DP】

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Promblem descriptio ...

  8. code forces 148D Bag of mice (概率DP)

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  9. 【CF】148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...

随机推荐

  1. SpringAOP与Redis搭建缓存

    近期项目查询数据库太慢,持久层也没有开启二级缓存,现希望采用Redis作为缓存.为了不改写原来代码,在此采用AOP+Redis实现. 目前由于项目需要,只需要做查询部分: 数据查询时每次都需要从数据库 ...

  2. js类型转换

    1.js中有六种基本类型,分别是object.number.string.Boolean.null.undefined,其中number.string.Boolean为基本类型,有时使用会强制转换成对 ...

  3. 如何在SharePoint 当中使用纯JSOM上传任意二进制文件(小于2MB)

    在微软的官方网站上有关于如何在SharePoint当中使用JS创建一个简单的文本文件的例子,经过我的思考我觉得结合Html5特性的浏览器,是完全可以通过JS来读取到文件的内容的(这一部分的内容请大家自 ...

  4. 如果你的SharePoint出现了,状态服务问题,InfoPath无法正常使用

    Create a new ‘State Service’ Service Application using Powershell February 14, 2012Leave a commentGo ...

  5. Ionic设置ion-slide-box不启用(不通过$ionicSlideBoxDelegate)

    猛地一看这个标题,可能觉得多此一举,直接$ionicSlideBoxDelegate. $getByHandle(handle). enableSlide(false)设置不就行了?是的,按理说就是这 ...

  6. lucky 的 时光助理(2)

    lucky小姐说:昨天晚上他喝醉了,发消息说他想我了,说他后悔了. 我很惊讶. 我问lucky:你们很久都没有联系, 突然说... 你怎么想. 没错,'他'就是lucky的前男友. lucky看着我, ...

  7. SQL Server 2008 R2:快速清除日志文件的方法

    本例,快速清理“students”数据库的日志,清理后日志文件不足1M. USE [master] GO ALTER DATABASE students SET RECOVERY SIMPLE WIT ...

  8. Shell中字符串分割的三种方法

    问题:对于’1,2,3,4,5’这样的字符串输出采用,分隔开的1 2 3 4 5 特征:在字符串中没有空格 解决方法1: #!/bin/bash var=’1,2,3,4,5’ var=${var// ...

  9. nginx 虚拟主机基于端口的搭建

    首先配置nginx.conf [root@localhost conf]# cat nginx.confworker_processes 1;user nginx nginx;error_log /a ...

  10. 异常处理之“The remote certificate is invalid according to the validation praocedure.”

    参考文章:http://brainof-dave.blogspot.com.au/2008/08/remote-certificate-is-invalid-according.html 参考文章:h ...