抓老鼠 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 仅仅.公主先抽,第一个抽出白老鼠的胜 ...
随机推荐
- (转)netty、mina性能对比分析
转自: http://blog.csdn.net/mindfloating/article/details/8622930 流行 NIO Framework netty 和 mina 性能测评与分析 ...
- ccf窗口
#include<iostream> #include<cstring> #include<algorithm> #include<vector> us ...
- 怎么使用response.write来做一个javascript的alert弹出窗口
Page.RegisterStartupScript("alert", "<script language=javascript>alert('添加成功'); ...
- Leetcode 94
/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode ...
- Leetcode 784
//这代码可真丑陋,但我学到了两点1:char和string可以无缝互相转换2:char可以直接加减数字进行转换string不行 class Solution { public: vector< ...
- K8S镜像删除及环境清理
环境清理: #删除所有容器sudo docker rm -f $(sudo docker ps -qa) #删除/var/etcd目录sudo rm -rf /var/etcd #删除/var/lib ...
- EL表达式、 jstl标签
https://www.cnblogs.com/zhaotiancheng/p/6391894.html https://blog.csdn.net/zdwzzu2006/article/detail ...
- C++基础——new与delete
本文目录 专业名称 new operator:new操作符,new表达式 operator new:new运算符 placement new:定位new delete operator:delete操 ...
- 6.pragma pack
下面两个结构体 struct One { double d; char c; int i; } struct Two { char c; double d; int i; } 在#pragma pac ...
- ZOJ 3829 Known Notation 贪心 难度:0
Known Notation Time Limit: 2 Seconds Memory Limit: 65536 KB Do you know reverse Polish notation ...