抓老鼠 codeForce 148D - Bag of mice 概率DP
设dp[i][j]为有白老鼠i只,黑老鼠j只时轮到公主取时,公主赢的概率。
那么当i = 0 时,为0
当j = 0时,为1
公主可直接取出白老鼠一只赢的概率为i/(i+j)
公主取出了黑老鼠,龙必然也要取出黑老鼠公主才能赢,跑出来的老鼠有两种可能
跑出来的是黑老鼠,公主赢的概率为dp[i][j] += j/(i+j)*(j-1)/(i+j-1)*(j-2)/(i+j-2)*dp[i][j-3].(j>=3)
跑出来的是白老鼠,公主赢的概率为dp[i][j] += j/(i+j)*(j-1)/(i+j-1)*i/(i+j-2)*dp[i-1][j-2].(j>=2)
贴代码:
#include <cstdio>
#define N 1005
double dp[N][N];
int main()
{
// freopen("in.c","r",stdin);
int w,b;
scanf("%d%d",&w,&b);
for(int i=; i<=w; ++i) dp[i][] =;
for(int i=; i<=b; ++i) dp[][i] =;
for(int i=; i<=w; ++i)
{
for(int j=; j<=b; ++j)
{
dp[i][j] = (double)i/(i+j);
if(j >= ) dp[i][j] += (double)j/(i+j)*(double)(j-)/(i+j-)*(double)(j-)/(i+j-)*dp[i][j-];
if(j >= ) dp[i][j] += (double)j/(i+j)*(double)(j-)/(i+j-)*(double)i/(i+j-)*dp[i-][j-];
}
}
printf("%.9lf\n",dp[w][b]);
return ;
}
抓老鼠 codeForce 148D - Bag of mice 概率DP的更多相关文章
- 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 ...
- 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 ...
- codeforces 148D Bag of mice(概率dp)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- Bag of mice(概率DP)
Bag of mice CodeForces - 148D The dragon and the princess are arguing about what to do on the New Y ...
- 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 ...
- 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 Round #105 D. Bag of mice 概率dp
http://codeforces.com/contest/148/problem/D 题目意思是龙和公主轮流从袋子里抽老鼠.袋子里有白老师 W 仅仅.黑老师 D 仅仅.公主先抽,第一个抽出白老鼠的胜 ...
随机推荐
- 用docker部署gitlab
docker hub官网下载gitlab速度太慢,改用国内镜像+中文版 docker pull registry.cn-hangzhou.aliyuncs.com/lab99/gitlab-ce-zh ...
- 为arm 编译包含gd的php5
1) 下载gd的各种依赖包. 但是不要下载gd本身,因为这是包含在php里的. 探索的时候也下载了 libvpx freetype,可惜最后的编译没过,就没有用上 2)编译各种(编译前记得把各种环境变 ...
- 如何将新项目添加到github仓库中?只需简单几步~即可实现
问题描述:新建了一个项目,如何将其设置为git项目?如何关联到github上的仓库? 只需简单几步,但前提是需要已经安装好了git,并且有github账户 本文使用IntelliJ IDEA 其他编辑 ...
- LeetCode--226--翻转二叉树
问题描述: 翻转一棵二叉树. 示例: 输入: 4 / \ 2 7 / \ / \ 1 3 6 9 输出: 4 / \ 7 2 / \ / \ 9 6 3 1 备注: 这个问题是受到 Max Howel ...
- 12月8日 周五 image_tag.
Overview of helpers provided by Action View 6.1 AssetTagHelper:用于generate html语言 image_tag ,return a ...
- DBeaver
DBeaver简介: 无意中得知DBeaver这个工具,觉得特别神奇,对我们目前工作特别有用,所以特别惊喜.(有点土包子没见过世面...) 借用百度百科:DBeaver是一个通用的数据库管理工具和 S ...
- hdu1358 kmp的next数组
For each prefix of a given string S with N characters (each character has an ASCII code between 97 a ...
- POJ-2251 Dungeon Master (BFS模板题)
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- Leetcode 73
class Solution { public: void setZeroes(vector<vector<int>>& matrix) { vector<vec ...
- 自定义Spark Partitioner提升es-hadoop Bulk效率——续
对于es 2.4版本,要能定制spark partitioner需要如下方式启动spark shell: spark-2.0.0-bin-hadoop2.6/bin/spark-shell --jar ...