Codeforces Round #105 (Div. 2) (D. Bag of mice(概率DP))
来源:互联网 发布:单片机红外发射 编辑:程序博客网 时间:2024/06/05 03:25
题目链接:点击打开链接
题意:
- 原来袋子里有w只白鼠和b只黑鼠
- 龙和王妃轮流从袋子里抓老鼠。谁先抓到白色老师谁就赢。
- 王妃每次抓一只老鼠,龙每次抓完一只老鼠之后会有一只老鼠跑出来。
- 每次抓老鼠和跑出来的老鼠都是随机的。
- 如果两个人都没有抓到白色老鼠则龙赢。王妃先抓。
- 问王妃赢的概率。
思路:概率DP, 用d[a][b][id]表示当前还剩a只白鼠, b只黑鼠, 轮到i == 0 ? 王妃 : 龙 抓老鼠了, 最终王妃赢的概率。 然后转移即可。
细节参见代码:
#include<cstdio>#include<cstring>#include<algorithm>#include<iostream>#include<string>#include<vector>#include<stack>#include<bitset>#include<cstdlib>#include<cmath>#include<set>#include<list>#include<deque>#include<map>#include<queue>#define Max(a,b) ((a)>(b)?(a):(b))#define Min(a,b) ((a)<(b)?(a):(b))using namespace std;typedef long long ll;typedef long double ld;const ld eps = 1e-9, PI = 3.1415926535897932384626433832795;const int mod = 1000000000 + 7;const int INF = 0x3f3f3f3f;// & 0x7FFFFFFFconst int seed = 131;const ll INF64 = ll(1e18);const int maxn = 1000 + 10;int T,n,m,vis[maxn][maxn][2],kase = 0, w, b;double d[maxn][maxn][2];double dp(int a, int b, int id) { double& ans = d[a][b][id]; if(a == 0) return 0; if(a != 0 && b == 0) { if(id) return 0; else return 1; } if(vis[a][b][id] == kase) return ans; vis[a][b][id] = kase; ans = 0; if(id) { if(b > 1) ans += dp(a, b-2, id^1) * (double)b/(double)(a + b) * (double)(b-1)/(double)(a+b-1); if(b > 0 && a > 0) ans += dp(a-1, b-1, id^1) * (double)b/(double)(a + b) * (double)a / (double)(a + b - 1); } else { if(a > 0) ans += (double)(a)/(a + b); if(b > 0) ans += dp(a, b-1, id^1) * (double)b / (double)(a + b); } return ans;}int main() { scanf("%d%d",&w,&b); ++kase; double ans = dp(w, b, 0); printf("%.10f\n",ans); return 0;}
1 0
- Codeforces Round #105 (Div. 2) (D. Bag of mice(概率DP))
- Codeforces Round #105 D. Bag of mice 概率dp
- CodeForces 148D. Bag of mice(概率dp啊 )
- CodeForces 148D Bag of mice(概率DP )
- Codeforces-148D Bag of mice (概率DP)
- CodeForces 148D Bag of mice(概率DP)
- Codeforces Round #105 (Div. 2)—Bag of mice 概率期望dp
- Codeforces Round #105 (Div. 2) D. Bag of mice
- Codeforces Round #105 (Div. 2) D. Bag of mice
- CodeForces - 148D. Bag of mice//Codeforces Round #105 (Div. 2)
- CF 148D Bag of mice (概率DP)
- code forces 148D Bag of mice (概率DP)
- (CF 148D Bag of mice)<简单概率DP>
- Codeforces 148D D Bag of mice(概率dp)
- codeforces 148D D. Bag of mice(概率dp)
- codeforces 148D. Bag of mice (概率与期望DP)
- Codeforces 148D Bag of mice(概率DP入门)
- codeforces 148D Bag of mice (概率DP)【博弈模板】
- 算法学习之二分查找
- 最大堆与最小堆的实现
- Go语言学习七:结构体
- 【LeetCode】9. Palindrome Number回文数判断
- ActiveMQ的基本使用
- Codeforces Round #105 (Div. 2) (D. Bag of mice(概率DP))
- 第三周个人所得税计算器
- 集合框架--Map集合
- 第3周项目4-用穷举法解决组合问题(4)三色球问题
- [iOS]MRC和ARC
- 臣妾做不到啊---记团队内首次尝试HOLACRACY管理会议
- DRAMSim2模拟器分析与应用
- PDO中执行SQL语句
- 关于大型网站技术演进的思考(十七)--网站静态化处理—满足静态化的前后端分离(9)