【题目链接】

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

【算法】

概率DP

f[w][b]表示还剩w只白老鼠,b只黑老鼠,公主胜利的概率,那么 :

1. 公主抓到白老鼠,概率为w/(w+b)

2. 公主抓到黑老鼠,那么龙也抓到黑老鼠,如果跑出来的老鼠是白颜色的,则概率为 : b / (w + b) * b / (w + b - 1) * w / (w + b - 2) * f[w-1][b-2]

否则,概率为 : b / (w + b) * (b - 1) / (w + b - 1) * (b - 2) / (w + b - 2) * f[w][b-3]

【代码】

#include<bits/stdc++.h>
using namespace std; int i,j,w,b;
double f[][]; double dp(int w,int b)
{
if (w < || b < ) return ;
if (f[w][b] != -) return f[w][b];
if (w == ) return f[w][b] = ;
if (w == && b == ) return f[w][b] = ;
f[w][b] = 1.0 * w / (w + b);
if (w >= && b >= ) f[w][b] += 1.0 * b / (w + b) * (b - ) / (w + b - ) * w / (w + b - ) * dp(w-,b-);
if (b >= ) f[w][b] += 1.0 * b / (w + b) * (b - ) / (w + b - ) * (b - ) / (w + b - ) * dp(w,b-);
return f[w][b];
} int main()
{ scanf("%d%d",&w,&b);
for (i = ; i <= w; i++)
{
for (j = ; j <= b; j++)
{
f[i][j] = -;
}
}
printf("%.9lf\n",dp(w,b)); return ;
}

【Codeforces 105D】 Bag of mice的更多相关文章

  1. 【codeforces 148D】 Bag of mice

    http://codeforces.com/problemset/problem/148/D (题目链接) 题意 包中有w个白鼠,b个黑鼠.公主和龙轮流画老鼠,公主先画,谁先画到白鼠谁就赢.龙每画完一 ...

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

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

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

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

  4. 【codeforces 793C】Mice problem

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

  5. 【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 ...

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

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

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

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

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

  9. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

随机推荐

  1. 同域之下子iframe的DOM控制问题

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

  2. 偶尔遇到的“The request was aborted:Could not create SSL/TLS secure channel.”怎么解决?

    项目中涉及到调用第三方的Https的WebService,我使用的是原始的HttpWebRequest. 代码中已经考虑到是Https,加上了SSL3协议,加上了委托调用.但偶尔还是会碰到 The r ...

  3. Hadoop2.6.5高可用集群搭建

    软件环境: linux系统: CentOS6.7 Hadoop版本: 2.6.5 zookeeper版本: 3.4.8 主机配置: 一共m1, m2, m3, m4, m5这五部机, 每部主机的用户名 ...

  4. MySQL笔试题搜罗

    一.有表如下 +------+---------+--------+ | name | subject | score | +------+---------+--------+ | 张三 | 数学 ...

  5. 【SQL】IN、EXISTS和表连接三者的效率比较

    一. IN和EXISTS比较 在许多基于基础表的查询中,为了满足一个条件,往往需要对另一个表进行查询.此时就会用到IN和EXISTS. 例如:查询departments表中存在的部门的人数. 1. 使 ...

  6. MatLab之Simulink之simple model

    Use Simulink to model a system and then simulate the dynamic behavior of that system. 1 Open in Comm ...

  7. Linux while和for循环简单分析

    一.循环重定向 最近遇到了一种新的循环重定向写法,由于没看懂,说以网上搜索了一下,然后再此分享一下: while read line do ...... done  < file 刚开始看,不明 ...

  8. SLAM: Ubuntu14.04_Kylin安装ROS-Indigo

    参考连接:ROS-Indigo版在Ubuntu上的安装第一步: 软件源配置 1. 增加下载源(增加ubuntu版的ros数据仓库,即下载源)(通用指令适合任何版本的ros) sudo sh -c 'e ...

  9. C# 去掉代码前边空格(格式化代码)

    private void button1_Click(object sender, EventArgs e) { textBox2.Text = ""; string str = ...

  10. 前端工具gulp2

    var gulp = require('gulp'); var less = require('gulp-less'); var htmlmin = require('gulp-htmlmin'); ...