poj2096Collecting Bugs(概率期望dp)
Time Limit: 10000MS | Memory Limit: 64000K | |
Total Submissions: 6400 | Accepted: 3128 | |
Case Time Limit: 2000MS | Special Judge |
Description
Two companies, Macrosoft and Microhard are in tight competition. Microhard wants to decrease sales of one Macrosoft program. They hire Ivan to prove that the program in question is disgusting. However, Ivan has a complicated problem. This new program has s subcomponents, and finding bugs of all types in each subcomponent would take too long before the target could be reached. So Ivan and Microhard agreed to use a simpler criteria --- Ivan should find at least one bug in each subsystem and at least one bug of each category.
Macrosoft knows about these plans and it wants to estimate the time that is required for Ivan to call its program disgusting. It's important because the company releases a new version soon, so it can correct its plans and release it quicker. Nobody would be interested in Ivan's opinion about the reliability of the obsolete version.
A bug found in the program can be of any category with equal probability. Similarly, the bug can be found in any given subsystem with equal probability. Any particular bug cannot belong to two different categories or happen simultaneously in two different subsystems. The number of bugs in the program is almost infinite, so the probability of finding a new bug of some category in some subsystem does not reduce after finding any number of bugs of that category in that subsystem.
Find an average time (in days of Ivan's work) required to name the program disgusting.
Input
Output
Sample Input
1 2
Sample Output
3.0000
Source
/*
一个软件有s个子系统,会产生n种bug。
某人一天发现一个bug,这个bug属于某种bug,发生在某个子系统中。
求找到所有的n种bug,且每个子系统都找到bug,这样所要的天数的期望。
需要注意的是:bug的数量是无穷大的,所以发现一个bug,
出现在某个子系统的概率是1/s,属于某种类型的概率是1/n。 f[i][j]表示已经找到i种bug,j个系统的bug,达到目标状态的天数的期望
f[n][s]=0;要求的答案是f[0][0];
f[i][j]可以转化成以下四种状态:
f[i][j],发现一个bug属于已经有的i个分类和j个系统。概率为(i/n)*(j/s);
f[i][j+1],发现一个bug属于已有的分类,不属于已有的系统.概率为 (i/n)*(1-j/s);
f[i+1][j],发现一个bug属于已有的系统,不属于已有的分类,概率为 (1-i/n)*(j/s);
f[i+1][j+1],发现一个bug不属于已有的系统,不属于已有的分类,概率为 (1-i/n)*(1-j/s);
写开之后移项并整理可得方程。
*/ #include<iostream>
#include<cstdio>
#include<cstring> #define N 1011 using namespace std;
int n,m,s,cnt;
double f[N][N],ans; inline int read()
{
int x=,f=;char c=getchar();
while(c>''||c<''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} int main()
{
n=read();s=read();
f[n][s]=;
for(int i=n;i>=;i--)
for(int j=s;j>=;j--)
if(i!=n || j!=s)
f[i][j]=(f[i+][j]*(n-i)*j+f[i][j+]*(s-j)*i+f[i+][j+]*(n-i)*(s-j)+n*s)/(n*s-i*j);
printf("%.4f\n",f[][]);
}
poj2096Collecting Bugs(概率期望dp)的更多相关文章
- 【POJ 2096】Collecting Bugs 概率期望dp
题意 有s个系统,n种bug,小明每天找出一个bug,可能是任意一个系统的,可能是任意一种bug,即是某一系统的bug概率是1/s,是某一种bug概率是1/n. 求他找到s个系统的bug,n种bug, ...
- 【BZOJ-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
- 【bzoj4832】[Lydsy2017年4月月赛]抵制克苏恩 概率期望dp
题目描述 你分别有a.b.c个血量为1.2.3的奴隶主,假设英雄血量无限,问:如果对面下出一个K点攻击力的克苏恩,你的英雄期望会受到到多少伤害. 输入 输入包含多局游戏. 第一行包含一个整数 T (T ...
- 【loj6191】「美团 CodeM 复赛」配对游戏 概率期望dp
题目描述 n次向一个栈中加入0或1中随机1个,如果一次加入0时栈顶元素为1,则将这两个元素弹栈.问最终栈中元素个数的期望是多少. 输入 一行一个正整数 n . 输出 一行一个实数,表示期望剩下的人数, ...
- Codeforces - 1264C - Beautiful Mirrors with queries - 概率期望dp
一道挺难的概率期望dp,花了很长时间才学会div2的E怎么做,但这道题是另一种设法. https://codeforces.com/contest/1264/problem/C 要设为 \(dp_i\ ...
- poj 2096 Collecting Bugs(期望 dp 概率 推导 分类讨论)
Description Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other ...
- 概率期望dp
对于概率dp,我一直都弄得不是特别明白,虽然以前也有为了考试去突击过,但是终究还是掌握得不是很好,所以决定再去学习一遍,把重要的东西记录下来. 1.hdu4405 Description 在一个 \( ...
- Codeforces 908 D.New Year and Arbitrary Arrangement (概率&期望DP)
题目链接:New Year and Arbitrary Arrangement 题意: 有一个ab字符串,初始为空. 用Pa/(Pa+Pb)的概率在末尾添加字母a,有 Pb/(Pa+Pb)的概率在末尾 ...
- [BZOJ4832]抵制克苏恩(概率期望DP)
方法一:倒推,最常规的期望DP.f[i][a][b][c]表示还要再攻击k次,目前三种随从个数分别为a,b,c的期望攻击英雄次数,直接转移即可. #include<cstdio> #inc ...
随机推荐
- HDU-1272小希的迷宫,并查集?其实不用并查集;
小希的迷宫 ...
- markman & psd
markman & psd MarkMan 设计稿标 & 测量神器 http://www.getmarkman.com/ https://www.jianshu.com/p/83af3 ...
- mysql 判断索引是否存在,存在则删除再创建索引(分表) 存储过程
1.分表5数据量大,执行所有分表修改,不包括5 CREATE PROCEDURE deleteIndex()BEGINDECLARE corpId CHAR (16);DECLARE flag INT ...
- NOIP2013提高组D2T3 华容道
n<=30 * m<=30 的地图上,0表示墙壁,1表示可以放箱子的空地.q<=500次询问,每次问:当空地上唯一没有放箱子的空格子在(ex,ey)时,把位于(sx,sy)的箱子移动 ...
- 51nod 1126 求递推序列的第N项 && hdu - 1005 Number Sequence (求周期)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1126 http://acm.hdu.edu.cn/showproblem ...
- 静态区间第k大(主席树)
POJ 2104为例(主席树入门题) 思想: 可持久化线段树,也叫作函数式线段树,也叫主席树(高大上). 可持久化数据结构(Persistent data structure):利用函数式编程的思想使 ...
- UVA 10006_Carmichael number
题意: N 为合数,对于任意一个在(1,N)之间的数满足 anmodn=a,则称N为Carmichael number,对于给定的N,判断是否为Carmichael number. 分析: 素数区间筛 ...
- int *ptr=(int *)(&a+1)问题的探讨
从网络上看到这样一道有意思的题目,是关于数组与指针的问题,描述如下: main() { ]={,,,,}; ); printf(),*(ptr-)); } 输出为:2,5 请解释以上代码的输出结果. ...
- Canon iP2780/iP2788 清零软件
http://www.drvsky.com/driver/iP2780_Tools.htm http://www.dyjqd.com/soft/6085.html#download http://v. ...
- E-SATA接口
1.VGA接口 VGA接口就是显卡上输出模拟信号的接口,也叫D-Sub接口,其实就是显示转移的接口,比如连接投影仪.连接电视等等.从外观上讲,VGA接口是一种D型接口,上面共有15针空,分成三排,每排 ...