Codeforces Round #105 D. Bag of mice 概率dp
http://codeforces.com/contest/148/problem/D
题目意思是龙和公主轮流从袋子里抽老鼠。袋子里有白老师 W 仅仅。黑老师 D 仅仅。公主先抽,第一个抽出白老鼠的胜利,龙每次抽的时候会随机跑出一仅仅老鼠。给出W和D要你求出公主胜利的概率。
对于dp[w][d]表示有w仅仅白老鼠d仅仅黑老鼠的情况下公主胜利的概率,假设公主第一次就抽出白鼠,概率是 w/(w+d) 。而假设公主没有抽到白鼠,要让公主胜利,龙也不能抽到白鼠。则是 rec = d/(w+d) * (d-1)/(w+d-1) 。
这是跑出来的老鼠可能是白的也可能是黑的。
假设是白鼠,则剩下w-1仅仅白鼠d-2仅仅黑鼠,然后再公主先手,概率是rec * w/(w+d-2) * dp[w-1][d-2]。 假设是黑鼠,则剩下w仅仅白鼠d-3仅仅黑鼠,相同公主先手。概率是rec * (d-2)/(w+d-2)
* dp[w][d-3];
终于得dp转移方程:
dp[i][j] = i / (i+j) + rec * (i / (i+j-2) * dp[i-1][j-2] + (j-2) / (i + j - 2) * dp[i][j-3]);
rec = j / (i + j) * (j - 1) / (i + j - 1);
/***********************************************
** problem ID : cf_#105D.cpp
** create time : Wed Jul 22 20:22:24 2015
** auther name : xuelanghu
** auther blog : blog.csdn.net/xuelanghu407
**********************************************/ #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; int n, m;
double dp[1010][1010]; int main () { cin >> n >> m; for (int i=0; i<=n; i++) {
dp[i][0] = 1.0;
}
for (int i=0; i<=m; i++) {
dp[0][i] = 0.0;
} for (int i=1; i<=n; i++) {
dp[i][1] = (double)i / (i+1);
for (int j=2; j<=m; j++) {
dp[i][j] = (double)i / (i+j);
double tmp = (double)j* (double)(j-1) / (i+j) / (i+j-1);
if (j>2) dp[i][j] += tmp * (double)(j-2) / (i+j-2) * dp[i][j-3];
dp[i][j] += tmp * (double)i / (i+j-2) * dp[i-1][j-2];
}
} printf("%.10lf\n", dp[n][m]); return 0;
} code
Codeforces Round #105 D. Bag of mice 概率dp的更多相关文章
- Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题
除非特别忙,我接下来会尽可能翻译我做的每道CF题的题面! Codeforces 148D 一袋老鼠 Bag of mice | 概率DP 水题 题面 胡小兔和司公子都认为对方是垃圾. 为了决出谁才是垃 ...
- 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 ...
- codeforces 148D Bag of mice(概率dp)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
- Bag of mice(概率DP)
Bag of mice CodeForces - 148D The dragon and the princess are arguing about what to do on the New Y ...
- 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 ...
- Codeforces 148D Bag of mice 概率dp(水
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 原来袋子里有w仅仅白鼠和b仅仅黑鼠 龙和王妃轮流从袋子里抓老鼠. 谁先抓到白色老师谁就赢 ...
- codeforces105d Bag of mice ——概率DP
Link: http://codeforces.com/problemset/problem/148/D Refer to: http://www.cnblogs.com/kuangbin/archi ...
- Educational Codeforces Round 13 E. Another Sith Tournament 概率dp+状压
题目链接: 题目 E. Another Sith Tournament time limit per test2.5 seconds memory limit per test256 megabyte ...
随机推荐
- ExtJs之表单(form)
--Form和Form Basic Extjs Form和Form Basic是两个东西,Form提供界面的展示,而Form Basic则提供数据的处理.验证等功能.每一个Form Panel在创建的 ...
- 洛谷——P2035 iCow
P2035 iCow 题目描述 被无止境的农活压榨得筋疲力尽后,Farmer John打算用他在MP3播放器市场新买的iCow来听些音乐,放松一下.FJ的iCow里存了N(1 <= N < ...
- Codeforces Round #300 Quasi Binary(DP)
Quasi Binary time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...
- Bomb Enemy -- LeetCode
Given a 2D grid, each cell is either a wall 'W', an enemy 'E' or empty '0' (the number zero), return ...
- BZOJ 2654 tree(二分答案+并查集)
[题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2654 [题目大意] 给你一个无向带权连通图,每条边是黑色或白色. 让你求一棵最小权的恰 ...
- 【最短路】【dijkstra】【二进制拆分】hdu6166 Senior Pan
题意:给你一张带权有向图,问你某个点集中,两两结点之间的最短路的最小值是多少. 其实就是dijkstra,只不过往堆里塞边的时候,要注意塞进去它是从集合中的哪个起始点过来的,然后在更新某个点的答案的时 ...
- CentOS 6.9配置网卡IP/网关/DNS命令详细介绍及一些常用网络配置命令(转)
一.IP 即时生效(重启后失效): ifconfig eth0 192.168.1.102 netmask 255.255.255.0 //添加IP地址 route add default gw 19 ...
- Vue 小项目的最佳实践
项目简介 目前一期只是为App内某个模块资讯模块文章的分享和APP下载,后续还会有更多的功能,为了项目可扩展.可伸缩结合了我以前的实践搭建了此项目项目地址,如果这个简单的项目能给您带来帮助请给小哥哥⭐ ...
- ORA-04030
ORA-04030: 在尝试分配...字节(...)时进程内存不足的原因分析及解决办法 正在使用的oracle 11g数据库,前天在用一段时间后(开始要较长时间才出现,后来较短时间就出现),频繁报OR ...
- python中子类调用父类的方法
1子类调用父类构造方法 class Animal(object): def __init__(self): print("init Animal class~") def run( ...