http://codeforces.com/problemset/problem/148/D (题目链接)

题意

  包中有w个白鼠,b个黑鼠。公主和龙轮流画老鼠,公主先画,谁先画到白鼠谁就赢。龙每画完一只老鼠,就会有另一只老鼠从包中跑出来。每只老鼠被画到以及跑出的概率相等,问公主获胜的概率。

Solution

  令${f_{0/1,i,j}}$表示此时公主/龙选,包中还剩i只白鼠,j只黑鼠,公主赢的概率。那么转移很显然:

$${f_{0,i,j}=\frac{i}{i+j}+\frac{j}{i+j}*f_{1,i,j-1}}$$

$${f_{1,i,j}=\frac{j}{i+j}*(\frac{i}{i+j-1}*f_{0,i-1,j-1}+\frac{j}{i+j-1}*f_{0,i,j-2})}$$

细节

  一个加号没打,看半天没看出来。。

代码

// codeforces148D
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define inf 1<<30
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std;

const int maxn=1010;
double f[2][maxn][maxn];
int n,m;

int main() {
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) f[0][i][0]=1;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=m;j++) {
			f[0][i][j]=(double)(i+j*f[1][i][j-1])/(i+j);
			f[1][i][j]=(double)(i*f[0][i-1][j-1])/(i+j-1);
			if (j>1) f[1][i][j]+=(double)((j-1)*f[0][i][j-2])/(i+j-1);
			f[1][i][j]*=(double)j/(i+j);
		}
	printf("%.9lf",f[0][n][m]);
	return 0;
}

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

  1. 【Codeforces 105D】 Bag of mice

    [题目链接] http://codeforces.com/contest/148/problem/D [算法] 概率DP f[w][b]表示还剩w只白老鼠,b只黑老鼠,公主胜利的概率,那么 : 1. ...

  2. 【CodeForces】【148D】Bag of mice

    概率DP kuangbin总结中的第9题 啊……题目给的数据只有白鼠和黑鼠的数量,所以我们只能在这个上面做(gao)文(D)章(P)了…… 明显可以用两种老鼠的数量来作为状态= = 我的WA做法: 令 ...

  3. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  4. 【CF148D】 Bag of mice (概率DP)

    D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  5. 【codeforces 793C】Mice problem

    [题目链接]:http://codeforces.com/contest/793/problem/C [题意] 给你每个点x轴移动速度,y轴移动速度; 问你有没有某个时刻,所有的点都"严格& ...

  6. 【42.86%】【codeforces 742D】Arpa's weak amphitheater and Mehrdad's valuable Hoses

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  7. 【47.95%】【codeforces 554C】Kyoya and Colored Balls

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【21.58%】【codeforces 746D】Green and Black Tea

    time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...

  9. Codeforces 148 D Bag of mice

    D. Bag of mice http://codeforces.com/problemset/problem/148/D time limit per test 2 seconds memory l ...

随机推荐

  1. 关于MySQL数据库优化的部分整理

    在之前我写过一篇关于这个方面的文章 <[原创]为什么使用数据索引能提高效率?(本文针对mysql进行概述)(更新)> 这次,主要侧重点讲下两种常用存储引擎. 我们一般从两个方面进行MySQ ...

  2. Python开发【第二篇】:Python基础知识

    Python基础知识 一.初识基本数据类型 类型: int(整型) 在32位机器上,整数的位数为32位,取值范围为-2**31-2**31-1,即-2147483648-2147483647 在64位 ...

  3. 十种MYSQL显错注入原理讲解(一)

    开篇我要说下,在<代码审计:企业级Web代码安全架构>这本书中讲十种MYSQL显错注入,讲的很清楚. 感兴趣请去读完,若处于某种原因没读还想了解,那请继续往下. 1.count,rand, ...

  4. AndroidProjects个人项目归纳

    AndroidProjects 个人总结归纳-目录大纲 Data Binding框架MVVM BaseView CollapseView 更新中... 项目地址:https://github.com/ ...

  5. H5 表格的结构

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  6. Dagger2 (三) 总结篇

    一.Dagger2注入原理 Dagger2以自动生成代码的形式,帮助我们构建依赖图,在使用依赖的时候方便清晰,这里说明一点,在我们使用Dagger2的时候,绝大多数错误都是编译器就会暴漏出来,这也就决 ...

  7. Windows 批处理设置dns ,解决能上qq不能开网页

    对于windows 7 @echo off netsh interface ip set dns "本地连接" static 114.114.114.114 primary net ...

  8. SQL Server 2012 新特性:包含数据库访问数据库引擎

    简单的说就是可以让包含用户访问其他数据库,那么来看看如何配置,并且验证一下:   USE test CREATE USER up1 WITH PASSWORD = 'zhuzhu' SELECT *  ...

  9. Linux 系统中的MySQL数据库默认区分大小写

    今天在开发中遇到这么个问题,将连接的数据库改为服务器上的时候(服务器是Linux系统的),程序跑起来后一直出错,总提示数据库的表找不到, 而打开数据库看该表明明是存在的,在我的印象中MySQL数据是不 ...

  10. linux基本知识2

    date:时间管理 linux时钟: 硬件时钟:hwclock -s:硬件时钟到系统时钟   -w:系统时钟到硬件时钟 系统时钟:date 如何查看是外部命令还是内部命令: type COMMAND ...