【CF】148D Bag of mice
http://codeforces.com/problemset/problem/148/D
题意:w个白b个黑,公主和龙轮流取,公主先取,等概率取到一个。当龙取完后,会等概率跳出一只。(0<=w, b<=1000)
#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N=1005;
double d[N][N][2];
int main() {
scanf("%d%d", &n, &m);
d[0][0][0]=0;
d[0][0][1]=1;
for(int i=1; i<=n; ++i) d[i][0][0]=d[i][0][1]=1;
for(int j=1; j<=m; ++j) d[0][j][1]=1;
for(int i=1; i<=n; ++i)
for(int j=1; j<=m; ++j) {
d[i][j][0]=(double)i/(i+j)+(1-d[i][j-1][1])*j/(i+j);
if(i==1 && j==1) d[i][j][1]=1;
else if(i>1 && j==1) d[i][j][1]=(double)i/(i+j);
else d[i][j][1]=(double)i/(i+j)+(((1.0-d[i-1][j-1][0])*i+(1.0-d[i][j-2][0])*(j-1))/(i+j-1))*j/(i+j);
}
//for(int k=0; k<2; ++k) for(int i=0; i<=n; ++i) for(int j=0; j<=m; ++j) printf("d[%d][%d][%d]:%.3f\n", i, j, k, d[i][j][k]);
printf("%.15f\n", d[n][m][0]);
return 0;
}
写完这题后发现一个sb问题QAQ i/(i+j) 默认调用整数的除法QAQ 没发现前我一直在纠结,我的思路完全没错啊QAQ可是为嘛有问题。最后是在写了后边的题发现了这个问题然后就QAQ解决了...
设$d[i][j][0]$表示公主先手有$i$个白$j$个黑能赢的概率,$d[i][j][1]$表示龙先手有$i$个白$j$个黑能赢的概率
显然
王妃抓时:
1、抓到白,P=i/(i+j)
2、抓到黑,P=j/(i+j)
d[i][j][0]=i/(i+j)+(1-d[i][j-1][1])*j/(i+j)
龙抓时:
抓到黑:P=j/(i+j)
跳出了白:P=i/(i+j-1)
跳出了黑:P=(j-1)/(i+j-1)
抓到白:P=i/(i+j)
d[i][j][1]=i/(i+j)+(((1-d[i-1][j-1][0])*i+(1-d[i][j-2][0])*(j-1))/(i+j-1))*j/(i+j)
自行理解= =
【CF】148D Bag of mice的更多相关文章
- CF 148D Bag of mice【概率DP】
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes Promblem descriptio ...
- CF 148D. Bag of mice (可能性DP)
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- CF 148D Bag of mice 概率dp 难度:0
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- codeforce 148D. Bag of mice[概率dp]
D. Bag of mice time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
- CF 148D Bag of mice 题解
题面 这是我做的第一道概率DP题: 做完后发现没有后效性的DP是真的水: 在这里说主要是再捋顺一下思路: 设f[i][j]表示有i只白鼠,j只黑鼠是获胜的概率: 显然:f[i][0]=1; 然后分四种 ...
- code forces 148D Bag of mice (概率DP)
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- Codeforces 148D Bag of mice:概率dp 记忆化搜索
题目链接:http://codeforces.com/problemset/problem/148/D 题意: 一个袋子中有w只白老鼠,b只黑老鼠. 公主和龙轮流从袋子里随机抓一只老鼠出来,不放回,公 ...
- 【leetcode】948. Bag of Tokens
题目如下: You have an initial power P, an initial score of 0 points, and a bag of tokens. Each token can ...
- 【LeetCode】948. Bag of Tokens 解题报告(Python)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 贪心算法 日期 题目地址:https://leetc ...
随机推荐
- 公众号开发——测试工具【ngrok】
工具下载:ngrok 目录清单: ngrok.exe ngrok.cfg run.bat 点击bat启动. 可修改域名,右键bat文件修改. 成功效果图: 注:80端口被占用了怎么办? —— ...
- java中文乱码解决方法汇总
public static void main(String[] argv){ try { System.out.println(“中文”);//1 ...
- oracle 11g r1 RAC增加新节点
在一套两节点的rac上增加一个新的节点,详细的操作记录如下: 已有节点RAC1,RAC2 一,环境及版本: 公司环境:Vmware Esxi 5.5 操作系统:Redhat 5.8 x86_64 ...
- linux c学习笔记----互斥锁属性
转自:http://lobert.iteye.com/blog/1762844 互斥锁属性 使用互斥锁(互斥)可以使线程按顺序执行.通常,互斥锁通过确保一次只有一个线程执行代码的临界段来同步多个线程. ...
- Intent传递对象的两种方法(Serializable,Parcelable) (转)
今天讲一下Android中Intent中如何传递对象,就我目前所知道的有两种方法,一种是Bundle.putSerializable(Key,Object);另一种是Bundle.putParcela ...
- Database.com SOQL and SOSL Reference
如下是关于 SOQ L与 SOSL 的相关链接: http://docs.database.com/dbcom/en-us/db_sosl_soql/sforce_api_calls_soql.htm ...
- HDU 3586 Information Disturbing 树形DP+二分
Information Disturbing Problem Description In the battlefield , an effective way to defeat enemies ...
- ios编码转换 国标 UTF-8
我们知道,使用NSURLConnection的代理方法下载网页,存到一个NSData中, NSMutableData *pageData; [pageData appendData:data]; 如果 ...
- sql 根据指定条件获取一个字段批量获取数据插入另外一张表字段中+MD5加密
/****** Object: StoredProcedure [dbo].[getSplitValue] Script Date: 03/13/2014 13:58:12 ******/ SET A ...
- WebAPI接口调用身份验证
Common public interface ICacheWriter { void AddCache(string key, object value, DateTime expDate); vo ...