【poj2096】Collecting Bugs
题目描述
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.
输入
输出
样例输入
1 2
样例输出
3.0000
题目大意
共有n种bug和s个系统,每天随机发现1个系统中的1种bug,问:发现所有种类的bug,且每个系统都发现bug的期望天数。
题解
期望dp
f[i][j] = f[i+1][j+1]*(n-i)/n*(s-j)/s + f[i][j+1]*i/n*(s-j)/s + f[i+1][j]*(n-i)/n*j/s + f[i][j]*i/n*j/s + 1
移项,合并同类项,化简
#include <cstdio>
double f[1002][1002];
int main()
{
int n , s , i , j;
scanf("%d%d" , &n , &s);
for(i = n ; i >= 0 ; i -- )
for(j = s ; j >= 0 ; j -- )
if(i != n || j != s)
f[i][j] = (f[i + 1][j + 1] * (n - i) * (s - j) + f[i][j + 1] * i * (s - j) + f[i + 1][j] * (n - i) * j + (n * s)) / (n * s - i * j);
printf("%.4lf\n" , f[0][0]);
return 0;
}
【poj2096】Collecting Bugs的更多相关文章
- 【POJ2096】Collecting Bugs 期望
[POJ2096]Collecting Bugs Description Ivan is fond of collecting. Unlike other people who collect pos ...
- 【poj2096】Collecting Bugs 期望dp
题目描述 Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other materia ...
- 【poj2096】 Collecting Bugs
http://poj.org/problem?id=2096 (题目链接) 题意 有一个程序,其中有s个子结构,每个子结构出bug的概率相等.bug总共分成n类,每种bug出现的概率相等.每天找出一个 ...
- 【POJ】【2096】Collecting Bugs
概率DP/数学期望 kuangbin总结中的第二题 大概题意:有n个子系统,s种bug,每次找出一个bug,这个bug属于第 i 个子系统的概率为1/n,是第 j 种bug的概率是1/s,问在每个子系 ...
- 【POJ 2096】 Collecting Bugs
[题目链接] http://poj.org/problem?id=2096 [算法] 概率DP [代码] #include <algorithm> #include <bitset& ...
- 【POJ 2096】Collecting Bugs 概率期望dp
题意 有s个系统,n种bug,小明每天找出一个bug,可能是任意一个系统的,可能是任意一种bug,即是某一系统的bug概率是1/s,是某一种bug概率是1/n. 求他找到s个系统的bug,n种bug, ...
- 【分享】Collecting all the cheat sheets
http://overapi.com/ 这个网站可以查询到所有与编程相关的各种技术,并给出详细的知识点(干货).
- poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 3523 Accepted: 1740 ...
- poj2096 Collecting Bugs(概率dp)
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 1792 Accepted: 832 C ...
随机推荐
- MySql错误代码1045的解决方案
错误代码 1045Access denied for user 'root'@'localhost' (using password:YES) 解决办法是重新设置root用户密码,在Windows平台 ...
- poj[2104]K-th Number
Description You are working for Macrohard company in data structures department. After failing your ...
- C/C++编程语言学习资料尽收眼底 电子书+视频教程
Visual C++(VC/MFC)学习电子书及开发工具下载请看这里 史无前例的网络最全最强C/C++资料索引: C/C++编程语言学习资料尽收眼底 电子书+视频教程 VC++/MFC(VC6)开发技 ...
- B树、B-树、B+树、B*树
B树 即二叉搜索树: 1.所有非叶子结点至多拥有两个儿子(Left和Right) 2.所有结点存储一个关键字 3.非叶子节点的左指针指向小于其关键字的字数,右指针指向大于其关键字的字数: 如: B树的 ...
- Python-04-基础
一.装饰器(decorator) 装饰器本质上也是函数,目的是为其他函数添加附加功能(装饰其他函数) Python通过使用装饰器来达到代码的开放与封闭. 原则: 不能修改被装饰函数的源代码. 不能修改 ...
- js小数点失精算法修正
在用js计算0.07*100时候竟然=7.000000000000001 关于js失精算法你都遇到哪些,让我们一起来细数一下吧 console.log(0.07*100); // 7.00000000 ...
- JS组件系列——封装自己的JS组件,你也可以
前言:之前分享了那么多bootstrap组件的使用经验,这篇博主打算研究下JS组件的扩展和封装,我们来感受下JQuery为我们提供$.Extend的神奇,看看我们怎么自定义自己的组件,比如我们想扩展一 ...
- iptables能够做什么
前言 在这两篇博文中已经具体分析了iptable的原理和在openwrt里面的实例 http://www.cnblogs.com/tanhangbo/p/4550455.html http://www ...
- 轻量级DAO层实践初体验
最近快被 Hibernate 给坑哭了,有了自己动手实现 ORM 映射 DAO 的冲动. 工作之余折腾了快一星期,总算是有点小成就. 现打算将过程记录下来,方便自己后续回顾填补遗漏. 1. 传统 JD ...
- HTML5 File API — 让前端操作文件变的可能
前言 在 HTML5 File API 出现之前,前端对于文件的操作是非常有局限性的,大多需要配合后端实现.出于安全角度考虑,从本地上传文件时,代码不可能获取文件在用户本地的地址,所以纯前端不可能完成 ...