CF 148D Bag of mice 题解
这是我做的第一道概率DP题;
做完后发现没有后效性的DP是真的水;
在这里说主要是再捋顺一下思路;
设f[i][j]表示有i只白鼠,j只黑鼠是获胜的概率;
显然:f[i][0]=1;
然后分四种情况:
1.先手刚好拿到白鼠:概率是i/(i+j);
2.先手拿到黑鼠,后手拿到了白鼠:概率为0;
3.先手拿到了黑鼠,后手拿到了也黑鼠,并且跑的是白鼠:概率是::dp[i][j]=j/(i+j)∗(j−1)/(i+j−1)∗i/(i+j−2)∗dp[i−1][j−2];
4.先手拿到了黑鼠,后手拿到了也黑鼠,并且跑的是黑鼠:概率是:dp[i][j]=j/(i+j)∗(j−1)/(i+j+1)∗(j−2)/(i+j−2)∗dp[i][j−3];
然后就可以AC掉了;
#include <bits/stdc++.h>
using namespace std;
double f[1010][1010];
int main()
{
int w,b;
scanf("%d%d",&w,&b);
for(register int i=1;i<=w;i++){
f[i][0]=1;
for(register int j=1;j<=b;j++){
f[i][j]=(double)i/(double)(i+j);
}
}
for(register int i=1;i<=w;i++){
for(register int j=1;j<=b;j++){
if(j>=2) f[i][j]=f[i][j]+(double)(f[i-1][j-2]*1.0000*j*(j-1)*i/(i+j)/(j+i-1)/(i+j-2));
if(j>=3) f[i][j]=f[i][j]+(double)(f[i][j-3]*1.0000*j*(j-1)*(j-2)/(i+j)/(i+j-1)/(i+j-2));
}
}
printf("%.9lf",f[w][b]);
}
CF 148D Bag of mice 题解的更多相关文章
- 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 ...
- 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 ...
- 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
http://codeforces.com/problemset/problem/148/D 题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个.当龙取完后,会等概率跳出一只.(0<= ...
- code forces 148D Bag of mice (概率DP)
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces 148D Bag of mice:概率dp 记忆化搜索
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公 ...
- CodeForces - 148D Bag of mice
http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...
- codeforces 148D Bag of mice(概率dp)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
随机推荐
- NOI 2017滚粗退役记
NOI 2017 游记 又到了OIer退役了的季节 Day -1 今天是报到日. 中午11点多的动车.动车上和dick32165401和runzhe2000谈笑风生.顺便用dick32165401的流 ...
- flask框架(六): 实现支持正则的路由
一:默认路由 @app.route('/user/<username>') @app.route('/post/<int:post_id>') @app.route('/pos ...
- 关于在mac上使用valet集成环境添加memcache扩展
由于业务要求需要使用到memcache,直接使用brew安装在phpinfo上面显示并没有加载成功,使用以下方法时我们需要先卸载之前已经安装完成的memcache brew unlink php70- ...
- super 和 this 的区别
一 this和super关键字区别 1.子类的构造函数如果要引用super的话,必须把super放在函数的首位.2.super(参数):调用基类中的某一个构造函数(应该为构造函数中的第一条语句)3.t ...
- python-matplotlib-1
Python图表绘制:matplotlib绘图库入门 matplotlib 简介 matplotlib 是python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制 ...
- SpringSecurity remember-me功能
1./login .and().formLogin().loginPage("/user/login.html") //在successHandler中,使用response返回登 ...
- GDAL OGR Tools
OGR2OGR ogr2ogr 使用文档 1. GeoJSON 转换 ShapeFile ogr2ogr -nlt POLYGON -skipfailures ground.shp ground.js ...
- Dev中GridView——背景颜色改变
DevExpress.XtraGrid.Views 设置指定行的背景颜色 1.事件:CustomDrawCell2.示例: private void gridView1_CustomDrawCell( ...
- WPF 键盘全局接收消息
1.========================================================================== 在c#中怎样禁用鼠标左键的使用,其实我们可以通 ...
- 通过ssh管道连接内网数据库(mysql)
公网连接内网数据库(如云数据库)时,通常需要白名单:如果不是白名单IP,通常需要一个跳板机(类似代理)来连接内网数据库, 下方以mysql为例(其他数据库基本一致): import pymysql a ...