CoderForce 148D-Bag of mice (概率DP求概率)
题目大意:美女与野兽在玩画鸽子的游戏。鸽子在用黑布遮住的笼子里,白色的有w只,黑色的有b只,每次拿出一只作画,谁先画到白色的鸽子谁就赢。美女首先画,因为野兽太丑,它每次画的时候都会吓跑一只鸽子,所有出笼子的鸽子都不在进去。求美女赢得概率。(设定假如没有人画到白色鸽子,算野兽赢)。
题目分析:这道题不难,很显然的概率DP。这是我第一次写概率DP,纪念一下。。。
代码如下:
# include<iostream>
# include<cstdio>
# include<vector>
# include<list>
# include<queue>
# include<cstring>
# include<set>
# include<map>
# include<string>
# include<cmath>
# include<algorithm>
using namespace std; double dp[1005][1005]; double DP(int w,int b)
{
if(dp[w][b]!=-1.0) return dp[w][b];
if(w<=0) return dp[w][b]=0.0;
if(b<=0) return dp[w][b]=1.0;
double res1=(double)w/(double)(w+b);
double res2=((double)b/(double)(w+b))*((double)(b-1)/(double)(w+b-1));
double t=0.0;
if(b-2>0)
t+=((double)(b-2)/(double)(w+b-2))*DP(w,b-3);
if(w-1>0)
t+=((double)(w)/(double)(w+b-2))*DP(w-1,b-2);
res2*=t;
return dp[w][b]=res1+res2;
} int main()
{
int w,b;
while(~scanf("%d%d",&w,&b))
{
for(int i=0;i<=w;++i)
for(int j=0;j<=b;++j)
dp[i][j]=-1.0;
printf("%.9lf\n",DP(w,b));
}
return 0;
}
CoderForce 148D-Bag of mice (概率DP求概率)的更多相关文章
- 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 ...
- HDU-4089 Activation (概率DP求概率)
题目大意:一款新游戏注册账号时,有n个用户在排队.每处理一个用户的信息时,可能会出现下面四种情况: 1.处理失败,重新处理,处理信息仍然在队头,发生的概率为p1: 2.处理错误,处理信息到队尾重新排队 ...
- HDU3853-LOOPS(概率DP求期望)
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- 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 ...
- CF 148D Bag of mice【概率DP】
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Promblem descriptio ...
- 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)
题意:给你w个白色小鼠和b个黑色小鼠,把他们放到袋子里,princess先取,dragon后取,princess取的时候从剩下的当当中任意取一个,dragon取得时候也是从剩下的时候任取一个,但是取完 ...
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
- CF 148D Bag of mice 题解
题面 这是我做的第一道概率DP题: 做完后发现没有后效性的DP是真的水: 在这里说主要是再捋顺一下思路: 设f[i][j]表示有i只白鼠,j只黑鼠是获胜的概率: 显然:f[i][0]=1; 然后分四种 ...
随机推荐
- MySQL Crash Course #15# Chapter 23. Working with Stored Procedures
以前写过类似的东西,用来自动生成数据. 你可以将 Stored Procedure 理解为可以重复使用的批处理文件. Stored Procedure 非常有用,我们应该尽可能地去使用它. 那么,应用 ...
- 浅谈elasticsearch 集群
elasticsearch 集群 摘要: elasticsearch 集群 搭建elasticsearch的集群 现在假设我们有3台es机器,想要把他们搭建成为一个集群 基本配置 每个节点都要进行这样 ...
- c++学习之map基本操作
map作为最常用的数据结构之一,用的好可以大幅度的提升性能. // java_cpp_perftest.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h& ...
- 散列表(HashTable)
散列表 i. 散列函数 i. 冲突解决 ii. 分离链表法 ii. 开放地址法 iii. 线性探测法 iii. 平方探测法 iii. 双散列 ii. 再散列 ii. 可扩散列 i. 装填因子:元素个数 ...
- C++面向对象高级开发课程(第二周)
1. 类中含有指针—— class with pointer member(s) ——的情况经常发生,典型的有:string 类. 2. STL中的 string 类太复杂,copy on write ...
- poj 3368 Frequent values -Sparse-Table
Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 16537 Accepted: 5981 Description You ...
- Sizeof与Strlen的区别【转】
本文转载自:http://www.cnblogs.com/carekee/articles/1630789.html Sizeof与Strlen的区别与联系 一.sizeof sizeof(.. ...
- MBR记录
mbr version: 1.6 boot code size: primary data size: extended data size: debug version: no bpb status ...
- return false break;
js中的return false; break; , , , , ]; var list2 = ['a', 'b', 'c', 'd']; ; j < list2.length; j++) { ...
- 【第三十六章】 metrics(4)- metrics-graphite
将metrics report给graphite(carbon-relay) 一.代码 1.pom.xml <!-- metrics-graphite --> <dependency ...