http://codeforces.com/problemset/problem/148/D

题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个。当龙取完后,会等概率跳出一只。(0<=w, b<=1000)

#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N=1005;
double d[N][N][2];
int main() {
scanf("%d%d", &n, &m);
d[0][0][0]=0;
d[0][0][1]=1;
for(int i=1; i<=n; ++i) d[i][0][0]=d[i][0][1]=1;
for(int j=1; j<=m; ++j) d[0][j][1]=1;
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j) {
d[i][j][0]=(double)i/(i+j)+(1-d[i][j-1][1])*j/(i+j);
if(i==1 && j==1) d[i][j][1]=1;
else if(i>1 && j==1) d[i][j][1]=(double)i/(i+j);
else d[i][j][1]=(double)i/(i+j)+(((1.0-d[i-1][j-1][0])*i+(1.0-d[i][j-2][0])*(j-1))/(i+j-1))*j/(i+j);
}
//for(int k=0; k<2; ++k) for(int i=0; i<=n; ++i) for(int j=0; j<=m; ++j) printf("d[%d][%d][%d]:%.3f\n", i, j, k, d[i][j][k]);
printf("%.15f\n", d[n][m][0]);
return 0;
}

  

写完这题后发现一个sb问题QAQ i/(i+j) 默认调用整数的除法QAQ 没发现前我一直在纠结,我的思路完全没错啊QAQ可是为嘛有问题。最后是在写了后边的题发现了这个问题然后就QAQ解决了...

设$d[i][j][0]$表示公主先手有$i$个白$j$个黑能赢的概率,$d[i][j][1]$表示龙先手有$i$个白$j$个黑能赢的概率

显然

王妃抓时:
1、抓到白,P=i/(i+j)
2、抓到黑,P=j/(i+j)
d[i][j][0]=i/(i+j)+(1-d[i][j-1][1])*j/(i+j)

龙抓时:
抓到黑:P=j/(i+j)
跳出了白:P=i/(i+j-1)
跳出了黑:P=(j-1)/(i+j-1)
抓到白:P=i/(i+j)

d[i][j][1]=i/(i+j)+(((1-d[i-1][j-1][0])*i+(1-d[i][j-2][0])*(j-1))/(i+j-1))*j/(i+j)

自行理解= =

【CF】148D Bag of mice的更多相关文章

  1. CF 148D Bag of mice【概率DP】

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Promblem descriptio ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. CF 148D Bag of mice 题解

    题面 这是我做的第一道概率DP题: 做完后发现没有后效性的DP是真的水: 在这里说主要是再捋顺一下思路: 设f[i][j]表示有i只白鼠,j只黑鼠是获胜的概率: 显然:f[i][0]=1; 然后分四种 ...

  6. code forces 148D Bag of mice (概率DP)

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  7. Codeforces 148D Bag of mice:概率dp 记忆化搜索

    题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公 ...

  8. 【leetcode】948. Bag of Tokens

    题目如下: You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can ...

  9. 【LeetCode】948. Bag of Tokens 解题报告(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心算法 日期 题目地址:https://leetc ...

随机推荐

  1. Gmail 账号找回办法

    前段时间一直在用GFW代理,结果发现GOOGLE账户的保护机制起用了,要给以前的手机号发消息,结果哪个号现在不用了,所以就登陆不进去了,非常扯淡,索性谷歌了下,得出如下的解决方案,完美解决,下次直接在 ...

  2. 使用getopt函数对windows命令行程序进行参数解析

    getopt()是libc的标准函数,很多语言中都能找到它的移植版本. // -b -p "c:\input" -o "e:\test\output" bool ...

  3. js 横幅播放

    js 横幅播放 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www ...

  4. hdu 4028 2011上海赛区网络赛H dp+map离散

    一开始用搜索直接超时,看题解会的 #include<iostream> #include<cstdio> #include<map> #include<cst ...

  5. poj 3264 【线段树】

    此题为入门级线段树 题意:给定Q(1<=Q<=200000)个数A1A2…AQ,多次求任一区间Ai-Aj中最大数和最小数的差 #include<algorithm> #incl ...

  6. PHP模拟POST请求,获取response内容

    /* * 模拟POST请求,获取response内容 */ protected function curl($url, $type, $header, $data) { $CURL_OPTS = ar ...

  7. 利用Aspose.Word控件和Aspose.Cell控件,实现Word文档和Excel文档的模板化导出

    我们知道,一般都导出的Word文档或者Excel文档,基本上分为两类,一类是动态生成全部文档的内容方式,一种是基于固定模板化的内容输出,后者在很多场合用的比较多,这也是企业报表规范化的一个体现. 我的 ...

  8. 让Web API支持$format参数的方法

    public static class WebApiConfig { public static void Register(HttpConfiguration config) { // Web AP ...

  9. 【jQuery 分页】jQuery分页功能的实现

    自写的jQuery实现分页功能的分页组件: 功能效果如下: 分页组件就是上图中的三部分, 分别放在表格上部  和下部 . 其中, 1>>>页面的代码如下: product.jsp 其 ...

  10. mysql一些有用的链接

    1.mysql安装:http://jingyan.baidu.com/article/f79b7cb35c0f439144023e38.html