【题目链接】

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. Java实现九宫格

    import java.util.Scanner; public class Sudoku { public static void main(String[] args) { System.out. ...

  2. python--6、logging模块

    logging 可用的日志级别: debug 10 info 20 warning 30 error 40 critical 50 logging默认参数: 默认日志级别是warning. 默认情况日 ...

  3. vs2015网站部署到iis后运行调试:无法在web服务器上启动调试的问题,403已禁止

    C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files C:\Windows\Microsoft.NET\Frame ...

  4. Deutsch lernen (12)

    1. hinweisen - wies hin - hingewiesen 向...指出,指明 auf etw.(A) hinweisen Ich möchte (Sie) darauf hiweis ...

  5. 机器学习:随机森林RF-OBB袋外错误率

    文章讲解比较详细,且有Python代码,可以作为有用的参考. 原文链接:http://blog.csdn.net/zhufenglonglove/article/details/51785220  参 ...

  6. DNN:逻辑回归与 SoftMax 回归方法

    UFLDL Tutorial 翻译系列:http://deeplearning.stanford.edu/wiki/index.php/UFLDL_Tutorial 第四章:SoftMax回归 简介: ...

  7. google浏览器 打印A4 最大宽度和高度px

    width: 1563px;(max) + = 分页了 + = 分页了 + = 没有分页 / ViewBag.results[].Count)); <td width="15%&quo ...

  8. day002 计算机基础之 操作系统和编程语言的分类

    &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp今天主要针对计算机基础中的操作系统和编程语言的分类进行了讲解. 操作系统 &nbsp ...

  9. Codeforces 899C - Dividing the numbers

    传送门:http://codeforces.com/contest/899/problem/C 本题是一个数学问题——集合划分. 将集合{1,2,...,n}划分成两个集合,使得两个集合的元素之和的绝 ...

  10. Android获取设备屏幕宽高像素值的两个方法

    private void get1() { Resources resources = this.getResources(); DisplayMetrics dm = resources.getDi ...