【Codeforces 105D】 Bag of mice
【题目链接】
http://codeforces.com/contest/148/problem/D
【算法】
概率DP
f[w][b]表示还剩w只白老鼠,b只黑老鼠,公主胜利的概率,那么 :
1. 公主抓到白老鼠,概率为w/(w+b)
2. 公主抓到黑老鼠,那么龙也抓到黑老鼠,如果跑出来的老鼠是白颜色的,则概率为 : b / (w + b) * b / (w + b - 1) * w / (w + b - 2) * f[w-1][b-2]
否则,概率为 : b / (w + b) * (b - 1) / (w + b - 1) * (b - 2) / (w + b - 2) * f[w][b-3]
【代码】
#include<bits/stdc++.h>
using namespace std; int i,j,w,b;
double f[][]; double dp(int w,int b)
{
if (w < || b < ) return ;
if (f[w][b] != -) return f[w][b];
if (w == ) return f[w][b] = ;
if (w == && b == ) return f[w][b] = ;
f[w][b] = 1.0 * w / (w + b);
if (w >= && b >= ) f[w][b] += 1.0 * b / (w + b) * (b - ) / (w + b - ) * w / (w + b - ) * dp(w-,b-);
if (b >= ) f[w][b] += 1.0 * b / (w + b) * (b - ) / (w + b - ) * (b - ) / (w + b - ) * dp(w,b-);
return f[w][b];
} int main()
{ scanf("%d%d",&w,&b);
for (i = ; i <= w; i++)
{
for (j = ; j <= b; j++)
{
f[i][j] = -;
}
}
printf("%.9lf\n",dp(w,b)); return ;
}
【Codeforces 105D】 Bag of mice的更多相关文章
- 【codeforces 148D】 Bag of mice
http://codeforces.com/problemset/problem/148/D (题目链接) 题意 包中有w个白鼠,b个黑鼠.公主和龙轮流画老鼠,公主先画,谁先画到白鼠谁就赢.龙每画完一 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【CF148D】 Bag of mice (概率DP)
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- 【codeforces 793C】Mice problem
[题目链接]:http://codeforces.com/contest/793/problem/C [题意] 给你每个点x轴移动速度,y轴移动速度; 问你有没有某个时刻,所有的点都"严格& ...
- 【42.86%】【codeforces 742D】Arpa's weak amphitheater and Mehrdad's valuable Hoses
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 【47.95%】【codeforces 554C】Kyoya and Colored Balls
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【21.58%】【codeforces 746D】Green and Black Tea
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- Codeforces 148 D Bag of mice
D. Bag of mice http://codeforces.com/problemset/problem/148/D time limit per test 2 seconds memory l ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
随机推荐
- 快速搭建tab
1. 布局文件代码: <?xml version="1.0" encoding="utf-8"?> <android.support.v4.a ...
- Java关于反射的用法
一. 首先是准备一个需要反射的类 public class Person { private String name; private int age; public String sex; publ ...
- Python+selenium第一个自动化脚本
第一个自动化脚本(用Python写的) from selenium import webdriver #从selenium导入webdriber driver=webdriber.Firefox() ...
- [Advanced Algorithm] - Exact Change
题目 设计一个收银程序 checkCashRegister(),其把购买价格(price)作为第一个参数 , 付款金额 (cash)作为第二个参数, 和收银机中零钱 (cid) 作为第三个参数. ci ...
- https ssl 总结
主要工作: 1)算法协商: 2)密钥交换: 3)身份认证: 4)数据通信: 1.2.3主要使用握手协议: 4使用记录协议. SSL协议可分为两层:记录协议.握手协议 SSL Record Protoc ...
- pycharm主题 变量颜色 自定义
File--Settings--Edtior--Color Schame-- Lanuage Defaults
- web开发——在网页中引用字体包(.ttf),即嵌入特殊字体
在写html时,有点时候需要显示一些特殊字体,不过这些特殊字体是系统一般不自带的,这时就需要我们自行加载要用的字体.方法如下: 1.首先在style里添加: @font-face { font-fam ...
- windows控制台(console)乱码
在cmd中输入 CHCP 65001,实操有效.记录一下 永久设置,代码如下: Windows Registry Editor Version 5.00 [HKEY_CURRENT_USER\Cons ...
- 复习MySQL⑤查询、常用函数
查询操作符列表 distinct操作符:用来消除重复记录. - 例: 查询fruits表中所有不重复的s_id select distinct s_id from fruits; 子查询:写在()中, ...
- lua_自己对“lua函数”知识点的总结
lua_自己对“lua函数”知识点的总结 1.lua函数的定义 --lua中,函数都是function类型的对象.(1)其可以被比较 (2)其可以赋值给一个对象(3)可以传递给函数(4)可以从函数中返 ...