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. 在多台服务器上简单实现Redis的数据主从复制(3)(转载)

    转载地址:http://www.cnblogs.com/liping13599168/archive/2011/04/14/2016226.html Redis的主从复制功能非常强大,一个master ...

  2. 【转载】 Pyqt QStackedWidget堆栈窗体

    转载地址: http://blog.csdn.net/a649518776/article/details/6636578 下面用代码实现上面窗口的设计 # -*- coding: utf-8 -*- ...

  3. 在python多进程中使用manager和Barrier

    注意:Barrier是PYTHON3才有的功能,在2中无法测试. #!/usr/bin/env python # -*- coding: utf-8 -*- import multiprocessin ...

  4. c++ 的 坑真多之头文件

    我发现类在做参数时,是可以不引用头文件,即不用#include"xxx.h"的,比如下面这样是没有问题的 #pragma once #include <string> ...

  5. A Study of WebRTC Security

    转自:http://webrtc-security.github.io/ A Study of WebRTC Security Abstract Web Real-Time Communication ...

  6. I帧 B帧 p帧 IDR帧的区别

    转自:http://blog.csdn.net/sphone89/article/details/8086071 IDR(Instantaneous Decoding Refresh)--即时解码刷新 ...

  7. 解决linux下unzip中文有乱码的问题

    xxx.zip 中有中文的文件,在linux下unzip就会有乱码. 解决办法:安装7zip 去http://sourceforge.net/projects/p7zip/files/latest/d ...

  8. Mysql数据库操作系统及配置参数优化

    数据库结构优化 表的水平拆分常用的水平拆分方法为:1.对 customer_id进行 hash运算,如果要拆分成5个表 则使用mod(customer_id,5)取出0-4个值2.针对不同的 hash ...

  9. MySQL5.7中新增的JSON类型的使用方法

    创建表json_test: CREATE TABLE json_test(id INT(11) AUTO_INCREMENT PRIMARY KEY,person_desc JSON)ENGINE I ...

  10. ie上如何兼容placeholder

    首先,判断浏览器是否支持placeholder属性: var input = document.createElement('input'); if("placeholder" i ...