CodeForces - 148D Bag of mice
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的更多相关文章
- Codeforces 148D Bag of mice:概率dp 记忆化搜索
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公 ...
- Codeforces 148D Bag of mice 概率dp(水
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
- codeforces 148D Bag of mice(概率dp)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
- 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 ...
- 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 ...
- 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 ...
- CF 148D Bag of mice【概率DP】
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Promblem descriptio ...
- code forces 148D Bag of mice (概率DP)
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 【CF】148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...
随机推荐
- ++a和a++的区别
另: short s = 4; s = s + 1; // 编译不通过.因为编译器无法判断等号右边的运算结果是否依然在等号左边的short类型范围内,容易丢失精度. s += 1; // 编译通过.+ ...
- DevExpress免费公开课,讲解即将发布的16.2新版功能
先报名后听课,开课时间12月底 报名地址:http://training.evget.com/open/detail/5115[适合人群]覆盖全领域,尤其适合课程适用人群:软件开发人员.企业中的数据分 ...
- swift-运算符
运算符:+ , - , * , / ,%, ++,-- OC和swiftch除了取模运算符,其他用法都一样 可以检测 //var num:UInt8 = 255 + 1 不可以检测 var num1: ...
- django 第三天 有关pip使用
软件应用开发的经典模型有这样几个环境:开发环境(development).集成环境(integration).测试环境(testing).QA验证,模拟环境(staging).生产环境(product ...
- 5种处理js跨域问题方法汇总(转载)
1.JSONP跨域GET请求 ajax请求,dataType为jsonp.这种形式需要请求在服务端调整为返回callback([json-object])的形式.如果服务端返回的是普通json对象.那 ...
- SQL server学习
慕课网sql server学习 数据库第一印象:desktop--web server--database server** 几大数据库:sql server.oracle database.DB2. ...
- protobuf的编译安装
github地址:https://github.com/google/protobuf支持多种语言,有多个语言的版本,本文采用的是在centos7下编译源码进行安装. github上有详细的安装说明: ...
- 安装.NET Framework进度条卡住不动的解决方案
VS在安装之前需要安装.NET Framework,我安装的是4.0版本.但是安装进度条到一半左右时就卡住不动了.前前后后重试多次,还有几次重新开机,但都没用. 开始还以为是安装的系统有问题.后来在网 ...
- Spark核心——RDD
Spark中最核心的概念为RDD(Resilient Distributed DataSets)中文为:弹性分布式数据集,RDD为对分布式内存对象的 抽象它表示一个被分区不可变且能并行操作的数据集:R ...
- 异步HTTPHandler的实现
使用APM的方式实现 using System; using System.Web; using System.Threading; class HelloWorldAsyncHandler : IH ...