【题目链接】

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. web通信之跨文档通信 postMessage

    index.html <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type&qu ...

  2. 基于 CC2530 的温度采集系统(未定稿)

    前言 最近在自学 Zigbee,每天的主要是任务是:看博客,看 CC2530 的 datasheet 和实践,熟悉片上的 SFR 以及控制板子. 学和做内容包括:IO.外部中断.Timer1/3/4. ...

  3. AI:AI是什么?

    古老的哲学对科学有永远的借鉴意义,科学上的咬文嚼字往往会让其丧失完备性. 一.AI是什么 你看起来它有多好,它就有多好.本质只能通过表象来描述,在色即是空的逻辑里,图灵测试也许是最精准的AI测试方式. ...

  4. iproute2和tc的高级路由用法

    #Linux advanced router ip link show #显示链路 ip addr show #显示地址(或ifconfig) ip route show #显示路由(route -n ...

  5. structure vs class in swift language

    Both class and structure can do: Define properties to store values Define methods to provide functio ...

  6. C#判断文件是否存在 //创建txt文件

    if(System.IO.File.Exists(@"")) { } if (System.IO.File.Exists(HttpRuntime.AppDomainAppPath ...

  7. vue.js的ajax和jsonp请求

    首先要声明使用ajax 在 router下边的 Index.js中 import VueResource from 'vue-resource'; Vue.use(VueResource); ajax ...

  8. Java基础学习笔记之:System类;Math类;Arrays类BigInteger,BigDecimal

    System类 在API中System类介绍的比较简单,我们给出定义,System中代表程序所在系统,提供了对应的一些系统属性信息,和系统操作.System类不能手动创建对象,因为构造方法被priva ...

  9. python基础1 格式化输出

    转载自:https://www.cnblogs.com/fat39/p/7159881.html %用法 1.整数输出 %o —— oct 八进制%d —— dec 十进制%x —— hex 十六进制 ...

  10. 在ecshop模板使用自定义函数

    https://blog.csdn.net/shaolinld/article/details/46400485 在ecshop模板使用自定义函数 可以增加自定义函数,在模板直接调用,例如: {$us ...