题目描述

Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stuff, he collects software bugs. When Ivan gets a new program, he classifies all possible bugs into n categories. Each day he discovers exactly one bug in the program and adds information about it and its category into a spreadsheet. When he finds bugs in all bug categories, he calls the program disgusting, publishes this spreadsheet on his home page, and forgets completely about the program. 
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 file contains two integer numbers, n and s (0<n,s<=1000).

输出

Output the expectation of the Ivan's working days needed to call the program disgusting, accurate to 4 digits after the decimal point.

样例输入

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的更多相关文章

  1. 【POJ2096】Collecting Bugs 期望

    [POJ2096]Collecting Bugs Description Ivan is fond of collecting. Unlike other people who collect pos ...

  2. 【poj2096】Collecting Bugs 期望dp

    题目描述 Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other materia ...

  3. 【poj2096】 Collecting Bugs

    http://poj.org/problem?id=2096 (题目链接) 题意 有一个程序,其中有s个子结构,每个子结构出bug的概率相等.bug总共分成n类,每种bug出现的概率相等.每天找出一个 ...

  4. 【POJ】【2096】Collecting Bugs

    概率DP/数学期望 kuangbin总结中的第二题 大概题意:有n个子系统,s种bug,每次找出一个bug,这个bug属于第 i 个子系统的概率为1/n,是第 j 种bug的概率是1/s,问在每个子系 ...

  5. 【POJ 2096】 Collecting Bugs

    [题目链接] http://poj.org/problem?id=2096 [算法] 概率DP [代码] #include <algorithm> #include <bitset& ...

  6. 【POJ 2096】Collecting Bugs 概率期望dp

    题意 有s个系统,n种bug,小明每天找出一个bug,可能是任意一个系统的,可能是任意一种bug,即是某一系统的bug概率是1/s,是某一种bug概率是1/n. 求他找到s个系统的bug,n种bug, ...

  7. 【分享】Collecting all the cheat sheets

    http://overapi.com/   这个网站可以查询到所有与编程相关的各种技术,并给出详细的知识点(干货).

  8. poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 3523   Accepted: 1740 ...

  9. poj2096 Collecting Bugs(概率dp)

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 1792   Accepted: 832 C ...

随机推荐

  1. Neutron 理解 (1): Neutron 所实现的虚拟化网络 [How Netruon Virtualizes Network]

    学习 Neutron 系列文章: (1)Neutron 所实现的虚拟化网络 (2)Neutron OpenvSwitch + VLAN 虚拟网络 (3)Neutron OpenvSwitch + GR ...

  2. c语言中的scanf在java中应该怎么表达,Scanner类。

    1 java是面向对象的语言 它没有像C语言中的scanf()函数,但是它的类库中有含有scanf功能的函数 2 java.util包下有Scanner类 Scanner类的功能与scanf类似 3 ...

  3. HTTP状态码对应

    HTTP的状态码 对于状态码大家如果经常在线买东西就能知道,我们买了东西就会有个订单状态:出库.发货中.送达中.送达等,其实这些状态就是状态码,只不过这些状态码都是文字.HTTP 响应的时候也有状态码 ...

  4. 国内外前端(js)开发框架对比

    国内外前端开发框架对比 首先我们先对目前国内外主流前端开发框架做一个基本的了解,之后再对他们进行一个直观的对比. Bootstrap Bootstrap(http://www.bootcss.com) ...

  5. win7中VS2010中安装CSS3.0问题解决方法

    win7中VS2010中安装CSS3.0问题解决方法   在安装Standards Update for VS2010 SP1后,VS2010中没有CSS3.0问题,以下是我的解决方法 1.首先去官网 ...

  6. openstack上创建vm实例后,状态为ERROR问题解决

    问题说明:在openstack上创建虚拟机,之前已顺利创建了n个centos6.8镜像的vm现在用ubuntu14.04镜像创建vm,发现vm创建后的状态为ERROR! 1)终端命令行操作vm创建 [ ...

  7. JavaScript toLowerCase() 方法 把字符串转换为小写

    定义和用法 toLowerCase() 方法用于把字符串转换为小写. 语法 stringObject.toLowerCase() 返回值 一个新的字符串,在其中 stringObject 的所有大写字 ...

  8. JavaScript的理解记录(5)

    ---接上篇: 三.DOM解析: 1.Document Object Model(DOM):是表示和操作HTML和XML文档内容的基础API;其中几个重要的类有:Document和Element,Te ...

  9. servlet的四个作用域

    作用域规定的是变量的有效期限,servlet有四个作用域对象,这里只说三个: 一. request作用域: 1.作用范围: 就是指从http请求发起,到服务器处理结束,返回响应的整个过程.在这个过程中 ...

  10. add添加

    s = {1,2,3,4,5,6,} 进行添加数据! s = {1,2,3,4,5,6,} s.add('s')#添加字符串's' s.add('3')#添加字符串'3' s.add(3)#添加3和字 ...