Codeforces 148D

考虑状态转移。。https://www.cnblogs.com/kuangbin/archive/2012/10/04/2711184.html
题意:原来袋子里有w只白鼠和b只黑鼠,龙和王妃轮流从袋子里抓老鼠,谁先抓到白色老鼠谁就赢
王妃每次抓一只老鼠,龙每次抓完一只老鼠之后会有一只老鼠跑出来。
王妃先抓,如果两个人都没有抓到白色老鼠则龙赢,问王妃赢的概率

思路:设dp[i][j]表示现在轮到王妃抓时有i只白鼠,j只黑鼠,王妃赢的概率

明显 dp[0][j]=0,0<=j<=b;因为没有白色老鼠了
dp[i][0]=1,1<=i<=w;因为都是白色老鼠,抓一次肯定赢了。
dp[i][j]可以转化成下列四种状态:
1、王妃抓到一只白鼠,则王妃赢了,概率为i/(i+j);
2、王妃抓到一只黑鼠,龙抓到一只白色,则王妃输了,概率为j/(i+j)*i/(i+j-1).
3、王妃抓到一只黑鼠,龙抓到一只黑鼠,跑出来一只黑鼠,则转移到dp[i][j-3],概率为j/(i+j)*(j-1)/(i+j-1)*(j-2)/(i+j-2);
4、王妃抓到一只黑鼠,龙抓到一只黑鼠,跑出来一只白鼠,则转移到dp[i-1][j-2],概率为j/(i+j)*(j-1)/(i+j-1)*i/(i+j-2);

当然后面两种情况要保证合法,即第三种情况要至少3只黑鼠,第四种情况要至少2只白鼠

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;
const int SZ = ;
double f[SZ][SZ];
//white->i->win black->j
int main()
{
int w, b;
scanf("%d %d", &w, &b);
for(int i = ; i <= w; i++) f[i][] = ;
for(double i = ; i <= w; i++)
for(double j = ; j <= b; j++)
{
int ii = (int)i, jj = (int)j;
f[ii][jj] += i / (i + j);//w
if(j >= ) f[ii][jj] += j/(i+j) * (j-)/(i+j-) * i/(i+j-) * f[ii-][jj-];//bb->w
if(j >= ) f[ii][jj] += j/(i+j) * (j-)/(i+j-) * (j-)/(i+j-) * f[ii][jj-];//bb->b
}
printf("%.9f\n", f[w][b]);
return ;
}

暑假集训 || 概率DP的更多相关文章

  1. [暑假集训--数位dp]LightOj1205 Palindromic Numbers

    A palindromic number or numeral palindrome is a 'symmetrical' number like 16461 that remains the sam ...

  2. [暑假集训--数位dp]hdu3709 Balanced Number

    A balanced number is a non-negative integer that can be balanced if a pivot is placed at some digit. ...

  3. [暑假集训--数位dp]hdu3555 Bomb

    The counter-terrorists found a time bomb in the dust. But this time the terrorists improve on the ti ...

  4. [暑假集训--数位dp]hdu3652 B-number

    A wqb-number, or B-number for short, is a non-negative integer whose decimal form contains the sub- ...

  5. [暑假集训--数位dp]hdu2089 不要62

    杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer).杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来,就可以消除个别的士司机和乘客的心理障碍, ...

  6. 暑假集训 || 树DP

    树上DP通常用到dfs https://www.cnblogs.com/mhpp/p/6628548.html POJ 2342 相邻两点不能同时被选 经典题 f[0][u]表示不选u的情况数,此时v ...

  7. 暑假集训 || 区间DP

    区间DP 经典石子合并问题V1    复杂度 On3 int a[SZ], sum[SZ], f[SZ][SZ]; int main() { int n; scanf("%d", ...

  8. 2018.8.17 2018暑假集训 关于dp的一些感想(以目前的知识水平)

    学了这么长时间的dp似乎还是不怎么样 谨以此篇文字记录一年以来与dp斗智斗勇的各种经历 关于dp(也就是动态规划)似乎对于每个OIer来说都是一个永远的噩梦. 刚刚开始学dp的时候完全搞不明白(只是觉 ...

  9. [暑假集训--数位dp]hdu5787 K-wolf Number

    Alice thinks an integer x is a K-wolf number, if every K adjacent digits in decimal representation o ...

随机推荐

  1. Android webkit 事件传递流程通道分析

    前言:基于android webview 上定制自己使用的可移植浏览器apk,遇到好多按键处理的问题.所以索性研究了一下keyevent 事件的传递流程. frameworks 层 keyevent ...

  2. django上课笔记7-jQuery Ajax 和 原生Ajax-伪造的Ajax-三种Ajax上传文件方法-JSONP和CORS跨域资源共享

    一.jQuery Ajax 和 原生Ajax from django.conf.urls import url from django.contrib import admin from app01 ...

  3. Struts2基本使用

    Struts2:本质servlet 1.接受页面参数 a.使用原生的ServletAPI接受(不推荐) request.getParameter(name) 获取元素request方式: --Http ...

  4. django-ckeditor表情包修改

    一.版本 Django==1.11 django-ckeditor==5.2.2 二.关键步骤 1.删除旧的ckeditor静态文件 所在目录:项目目录下的static文件夹下的ckditor文件夹 ...

  5. touch的基本用法

    touch的基本功能是改变文件的时间戳,以下是三种常用用法: 1.创建一个空文件 以当前时间为时间戳创建一个空文件.$ touch touch.txt //touch.txt不存在 2.更改文件时间戳 ...

  6. 鸟哥私房菜基础篇:Linux 档案与目录管理习题

    猫宁!!! 参考链接:http://linux.vbird.org/linux_basic/0220filemanager.php 鸟哥是为中国信息技术发展做出巨大贡献的人. 1-什么是绝对路径与相对 ...

  7. iOS NSUserDefaults [setValue:forKey:] [setObject:forKey:] <Objc> setValue(_,forKey:) set(_,forKey) <Swift 3>

    前者其实是NSObject都可以调用的KVC方法,后者才是NSUserDefaults的实例方法: 这里参数的类型是nullable id,但是我建议你在传null的时候慎重考虑,否则你的应用就可能面 ...

  8. pyinstaller模块

    应用场景: 1 把一些python脚本推广到更多机器上运行,但无法保证他们都有安装python解释器,所以,打包可以免去这一障碍 win: 安装: 在cmd中运行pip install pyinsta ...

  9. h5-17-元素拖放

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

  10. h5-35-ajax轮询实现推送效果

    data.txt { "number1":1200, } index.html <!DOCTYPE html> <html> <head> &l ...