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. 《连载 | 物联网框架ServerSuperIO教程》-4.如开发一套设备驱动,同时支持串口和网络通讯。附:将来支持Windows 10 IOT

    1.C#跨平台物联网通讯框架ServerSuperIO(SSIO)介绍 <连载 | 物联网框架ServerSuperIO教程>1.4种通讯模式机制. <连载 | 物联网框架Serve ...

  2. getRequestDispatcher()与sendRedirect()的区别

    1.request.getRequestDispatcher()是请求转发,前后页面共享一个request ; response.sendRedirect()是重新定向,前后页面不是一个request ...

  3. jQuery orbit 幻灯片

    在线实例 默认 带缩略图 带描述 使用方法 <div class="wrap" style="width: 565px; height: 290px; margin ...

  4. 配置eclipse J2EE环境

    早已习惯使用eclipse做Java相关的开发,因为之前安装的是RCP版本,今天发现对于J2EE的开发,在perference中居然没有Axis2的支持,需要添加J2EE的支持插件,特在此说明安装方式 ...

  5. 用java单例模式实现面板切换

    1.首先介绍一下什么是单例模式: java单例模式是一种常见的设计模式,那么我们先看看懒汉模式: public class Singleton_ { //设为私有方法,防止被外部类引用或实例 priv ...

  6. safari 浏览器window.history.go(-1)运行无效解决办法

    这几天做了几个手机端app的wap页面,做完之后发现一个问题,那就是ios系统下的safari浏览器不支持window.history.go(-1)..无语... 解决方法很简单!加上return f ...

  7. IO流的登录与注册

    import java.io.BufferedReader;import java.io.BufferedWriter;import java.io.File;import java.io.FileR ...

  8. [Erlang 0128] Term sharing in Erlang/OTP 下篇

    继续昨天的话题,昨天提到io:format对数据共享的间接影响,如果是下面两种情况恐怕更容易成为"坑", 呃,恰好我都遇到过; 如果是测试代码是下面这样,得到的结果会是怎样?猜! ...

  9. [Erlang 0110] Erlang Abstract Format , Part 1

    Erlang Abstract Format并不难懂,只是枯燥一点罢了,如果把Abstract Format的文档翻译出来,其实就是Erlang教科书中语法入门的部分. Erlang Abstract ...

  10. MongoDB学习笔记一—简介

    MongoDB简介 MongoDB在功能和复杂性之间取得了很好的平衡,并且大大简化了原先十分复杂的任务,它具备支撑今天主流web应用的关键功能:索引.复制.分片.丰富的查询语法,特别灵活的数据模型.与 ...