题意:

有s个系统,n种bug,小明每天找出一个bug,可能是任意一个系统的,可能是任意一种bug,即是某一系统的bug概率是1/s,是某一种bug概率是1/n。 求他找到s个系统的bug,n种bug,需要的天数的期望。~~题意很难懂··真的很难懂···~~

题目:

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

Input file contains two integer numbers, n and s (0 < n, s <= 1 000).

Output

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

Sample Input

1 2

Sample Output

3.0000

分析:

基础的概率dp。
令f[i][j]为当前已经找出i种bug,j个系统的,要到达目标状态(n,s)的期望天数。显然f[n][s]=0;,因为已经达到目标了。而dp[0][0]就是我们要求的答案。
考虑一下状态的转移根据题意,每个dp[i][j] 之后可以达到的状态有四种。
1.转移到[i+1][j]的概率为(n-i)/n* j/s
2.转移到[i][j+1]的概率为i/n*(s-j)/s
3.转移到[i+1][j+1]的概率为(n-i)/n*(s-j)/s
4.转移到[i][j]的概率为i/n*j/s
f[i][j]=(n-i)/n*j/s*f[i+1][j]+i/n*(s-j)/s*f[i][j+1]+f[i+1][j+1]*(n-i)/n*(s-j)/s+f[i][j]*i/n*j/s
移一下项
(1-i/n*j/s)*f[i][j]=(n-i)/n*j/s*f[i+1][j]+i/n*(s-j)/s*f[i][j+1]+f[i+1][j+1]*(n-i)/n*(s-j)/s
然后把左边的除过去得
f[i][j]=((n-i)/n*j/s*f[i+1][j]+i/n*(s-j)/s*f[i][j+1]+f[i+1][j+1]*(n-i)/n*(s-j)/s)/(1-i/n*j/s)
然后整理一下得
f[i][j]=(f[i+1][j]*(n-i)*j+f[i][j+1]*(s-j)*i+f[i+1][j+1]*(n-i)*(s-j)+n*s)/(n*s-i*j);

AC代码

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int M=1000+100;
double f[M][M];
int n,s;
int main()
{while(~scanf("%d%d",&n,&s)){memset(f,0,sizeof(f));for(int i=n; i>=0; i--)for(int j=s; j>=0; j--){if(i==n&&j==s)continue;f[i][j]=(f[i+1][j]*(n-i)*j+f[i][j+1]*(s-j)*i+f[i+1][j+1]*(n-i)*(s-j)+n*s)/(n*s-i*j);}printf("%.4f\n",f[0][0]);}return 0;
}

Collecting Bugs POJ - 2096(基础概率dp+期望模板)相关推荐

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

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

  2. spoj Favorite Dice(概率dp+期望)

    题意: 摇一个n面的骰子,问每一面都被摇到的次数期望是多少. 题解: 概率dp往往都是倒着推 我们设dp[x]表示已经摇到了x个面,还要摇的概率次数 那么dp[n] = 0(即一次还没摇) dp[0] ...

  3. poj 1322 Chocolate (概率dp)

    ///有c种不同颜色的巧克力.一个个的取.当发现有同样的颜色的就吃掉.去了n个后.到最后还剩m个的概率 ///dp[i][j]表示取了i个还剩j个的概率 ///当m+n为奇时,概率为0 # inclu ...

  4. 借助树的概率dp(期望)+数学-好题-hdu-4035-Maze

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4035 题目意思: 有n个房间,有n-1条通道连接这n个房间(每两个房间之间有且只有一条路,所以实际上 ...

  5. HDU 4336 Card Collector(状压 + 概率DP 期望)题解

    题意:每包干脆面可能开出卡或者什么都没有,一共n种卡,每种卡每包爆率pi,问收齐n种卡的期望 思路:期望求解公式为:$E(x) = \sum_{i=1}^{k}pi * xi + (1 - \sum_ ...

  6. ZOJ 3380 Patchouli's Spell Cards [基础概率DP+大数]

    Patchouli's Spell Cards Time Limit: 7 Seconds      Memory Limit: 65536 KB Patchouli Knowledge, the u ...

  7. 概率dp 期望 逆推

    题目大意: 从起点0点开始到达点n,通过每次掷色子前进,可扔出1,2,3,4,5,6这6种情况,扔到几前进几,当然对应飞行通道可以通过x直达一点y,x<y,计算到达n点或超过n 点要扔色子的次数 ...

  8. 【原创】概率DP总结 by kuangbin

    概率DP主要用于求解期望.概率等题目. 转移方程有时候比较灵活. 一般求概率是正推,求期望是逆推.通过题目可以体会到这点. 首先先推荐几篇参考的论文: <信息学竞赛中概率问题求解初探> & ...

  9. 【BZOJ - 3036】绿豆蛙的归宿(概率DAG图dp,拓扑排序,概率dp,期望的线性性)

    题干: 随着新版百度空间的下线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 给出一个有向无环的连通图,起点为1终点为N,每条边都有一个长度.绿豆蛙从起点出发,走向终点. 到达每一个顶点时,如 ...

最新文章

  1. Linux内核网络栈1.2.13-网卡设备的初始化流程
  2. C - Catch That Cow(BFS)
  3. Configuration类在网页实现对web.config的修改[转]
  4. 【例3-4】求后序遍历
  5. 阿里《Java开发手册》最新嵩山版发布!
  6. 6-Spring Boot缓存管理
  7. 【spine】原理介绍和程序实现
  8. web 前端绘制折线_html5绘制折线图
  9. 自定义服务器控件的元数据属性(MSDN)
  10. 拓端tecdat|R语言主成分分析(PCA)葡萄酒可视化:主成分得分散点图和载荷图
  11. 手机java版怎么换皮肤_手机QQ皮肤更换方法(安卓版)
  12. 做python少儿编程教程-基于海龟编辑器python少儿编程
  13. Win10字体模糊怎么办?
  14. 在谷歌下面打开之后显示金山毒霸页面
  15. 弹力弹珠java_Java趣味小程序:打弹珠
  16. oracle获取今天是周几,根据DateTime来获取当天是周几(已完结)
  17. 苹果账户登录_iOS 13的通过 Apple 登录第三方应用
  18. 数独终局生成及残局求解
  19. Android Button英文全部大写问题
  20. 选择OA,终极“避雷”方法来啦!

热门文章

  1. Ubuntu之SVN客户端安装+使用
  2. Android之安全退出应用程序的几种方式
  3. 《零基础看得懂的C语言入门教程 》——(九)C语言二维数组与循环嵌套
  4. 《零基础看得懂的C语言入门教程 》——(八)了解基本数组还不是那么简单
  5. c++中stringstream_文史哲与艺术中的数学_智慧树章节答案
  6. bpmn如何查看代码 idea_提高程序员效率的IDEA插件推荐(五大神器)
  7. 金蝶显示服务器异常,金蝶提示云服务器异常
  8. ubuntu安装mysql_Ubuntu18.04下安装MySQL
  9. matlab提示未定义wc,WooCommerce 教程:修复致命错误调用未定义的函数wc_get_order() - WooCommerce 微站...
  10. java对象实例_深入理解Java对象实例生成的例子!(转)