题目描述

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;
}

转载于:https://www.cnblogs.com/GXZlegend/p/6200476.html

【poj2096】Collecting Bugs 期望dp相关推荐

  1. [POJ2096] Collecting bugs

    传送门:>Here< 题意:有n种病毒存在于s个子任务中.每个子任务中的病毒数量可以看做无限.每天可以发现一个病毒,问在所有的s个子任务中,总共发现满n种病毒的期望时间 解题思路: 期望D ...

  2. Collecting Bugs (DP期望)

    题意:一个软件有s个子系统,会产生n种bug,某个人一天发现一个bug,这个bug属于某种bug,发生在某个子系统里.求找到所有的n种bug和s个子系统所需的天数的数学期望.(程序中的bug数量几乎是 ...

  3. 插头DP 概率DP / 期望DP

    插头DP && 概率DP / 期望DP 写在前面: 插头DP P5056 [模板]插头dp 手写哈希表的方法: 拉链法的代码如下: 开放寻址法的代码如下: 接下来是这道题的代码实现: ...

  4. POJ 2096 Collecting Bugs:期望dp

    题目链接:http://poj.org/problem?id=2096 题意: 有一个程序猿,他每天都会发现一个bug. bug共有n个种类.属于某一个种类的概率为1/n. 有s个子系统,每个bug属 ...

  5. 【POJ - 2096】Collecting Bugs(概率dp)

    题干: Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material ...

  6. luogu P4745 [CERC2017]Gambling Guide(期望DP + 最短路实现)

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 P4745 [CERC2017]Gambling Guide(期望DP + 最短路实现) Weblin ...

  7. [SCOI2008]奖励关(期望dp)

    你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必须在抛出下一个宝物之前做出选择,且现在决定不吃的宝物以后也不能再吃). 宝 ...

  8. 【bzoj4318】OSU! 期望dp

    题目描述 osu 是一款群众喜闻乐见的休闲软件.  我们可以把osu的规则简化与改编成以下的样子:  一共有n次操作,每次操作只有成功与失败之分,成功对应1,失败对应0,n次操作对应为1个长度为n的0 ...

  9. 【loj6342】跳一跳 期望dp

    题目描述 一个人从 $1$ 开始向 $n$ 跳,在 $i$ 时会等概率跳到 $i,i+1,...,n$ 之一.求从 $1$ 跳到 $n$ 的期望步数. $n\le 10^7$ . 题解 期望dp傻逼题 ...

最新文章

  1. 怎么设计一个好的数据库
  2. 阮一峰es6电子书_ES6理解进阶【大前端高薪训练营】
  3. vue - blog开发学习2
  4. 好戏连台,BCH独领风骚
  5. MTK平台性能优化---(1)综述
  6. 疑似iPhone XI内部设计图曝光:这个造型爱不起来
  7. 数据集如何影响作物病害识别的有效性
  8. 查看uboot变量地址_华为FIT AP通过Uboot切换FAT模式
  9. 计算机建模报告,计算机三维建模及分析实验报告单.doc
  10. 【CSON原创】javascript图片滚动效果发布
  11. 如何破解无线网络密码(无线网络密码破解)
  12. React中Video播放器的使用
  13. ZUC密码(C语言实现)
  14. 全能扫描王(一款识别率超高的OCR识别APP)
  15. 城市地铁类毕业论文文献包含哪些?
  16. 微信小程序Token登录验证
  17. 苹果公司的电脑产品及其历史
  18. 基于springboot的高校疫情打卡上报系统设计与实现 文档+项目源码及数据库文件+演示视频
  19. php 数组 按拼音首字母 排序 并分组
  20. 六款视频剪辑神器,做影视剪辑短视频事半功倍,15天有3000

热门文章

  1. 如果编程语言是女孩,你最喜欢哪一个?
  2. 「入坑」前端开发,我有一些经验想和你分享
  3. Web前端是什么?大牛推荐的高效学习路线,减少2倍时间
  4. python3 logging模块_python3中使用logging模块写日志,中文乱码,如何解决?
  5. 传感器工作原理_荧光氧气传感器工作原理简介
  6. mybatis中文文档_成神之路!缓存+MyBatis+MySQL+Spring全家桶+分布式技术实战合集
  7. 修改 decimal 默认值为0.00 sql_书写高性能SQL语句技巧,网友都说好
  8. redis 用户订单缓存_Redis实战(12)-基于Key失效和定时任务实现订单支付超时自动失效...
  9. maya为什么不能导出fbx_Maya在操作中最容易出现的几个问题,现在注意还来得及...
  10. php清除输出缓冲,php如何清除缓冲区