题干:

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

题目大意:

一个软件有s个子系统,会产生n种bug。某人一天一定会发现一个bug,这个bug属于某种bug,发生在某个子系统中。求找到所有的n种bug,且每个子系统都找到bug,这样所要的天数的期望。

解题报告:

需要注意的是:bug的数量是无穷大的,所以发现一个bug,出现在某个子系统的概率是1/s,属于某种类型的概率是1/n。

又有:期望可以分解成多个子期望的加权和,权为子期望发生的概率,即 E(aA+bB+...) = aE(A) + bE(B) +...

以下题解来自kuangbin:

dp[i][j]表示已经找到i种bug,j个系统的bug,达到目标状态的天数的期望dp[n][s]=0;要求的答案是dp[0][0];dp[i][j]可以转化成以下四种状态:dp[i][j],发现一个bug属于已经有的i个分类和j个系统。概率为(i/n)*(j/s);dp[i][j+1],发现一个bug属于已有的分类,不属于已有的系统.概率为 (i/n)*(1-j/s);dp[i+1][j],发现一个bug属于已有的系统,不属于已有的分类,概率为 (1-i/n)*(j/s);dp[i+1][j+1],发现一个bug不属于已有的系统,不属于已有的分类,概率为 (1-i/n)*(1-j/s);整理便得到转移方程

注意不能用注释的那个代码,因为没有整理,所以等号左侧和右侧都有dp[i][j],这样是不行的。

AC代码:

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 2e5 + 5;
int n,s;
double dp[1555][1555];
int main()
{cin>>n>>s;dp[n][s]=0;for(int i = n; i>=0; i--) {for(int j = s; j>=0; j--) {if(i == n && j == s) continue;
//          dp[i][j] = 1 + dp[i+1][j] * (n-i)*j/n/s + dp[i][j] * i*j/n/s + dp[i][j+1] *i*(s-j)/n/s + dp[i+1][j+1]*(n-i)*(s-j)/n/s;dp[i][j]=((n-i)*j*dp[i+1][j]+(n-i)*(s-j)*dp[i+1][j+1]+i*(s-j)*dp[i][j+1]+n*s)/(n*s-i*j);}}printf("%.4f\n",dp[0][0]);return 0 ;
}

【POJ - 2096】Collecting Bugs(概率dp)相关推荐

  1. Collecting Bugs POJ - 2096(基础概率dp+期望模板)

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

  2. POJ 2096 Collecting Bugs:期望dp

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

  3. poj 3071 Football(概率dp)

    http://poj.org/problem? id=3071 大致题意:有2^n个足球队分成n组打比赛.给出一个矩阵a[][],a[i][j]表示i队赢得j队的概率.n次比赛的流程像这样France ...

  4. 【poj2096】Collecting Bugs 期望dp

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

  5. Collecting Bugs (DP期望)

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

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

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

  7. 关于概率dp的个人理解与总结

    原文来自:http://blog.csdn.net/wdcjdtc/article/details/38424029 首先,概率dp主要解决的是关于概率问题和期望问题的求解. 难点和普通dp一样在于d ...

  8. poj 1322 Chocolate (概率dp)

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

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

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

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

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

最新文章

  1. freemarker ftl模板_Spring Boot2 系列教程(十)Spring Boot 整合 Freemarker
  2. [XSY3112] 接水果(树上包含路径,整体二分,扫描线)
  3. 对没有标记为安全的activex控件进行初始化和脚本运行_RASP攻防 —— RASP安全应用与局限性浅析...
  4. BLE4.0教程四 新增特征值(CC2541)
  5. 微信小程序开发学习笔记001--认识微信小程序,第一个微信小程序
  6. 关于java构造方法的描述_在JAVA语言中,下面关于构造函数描述正确的是()
  7. 转 windows核心编程 学习笔记 目录
  8. php tr td,php-基于tr计数的Td / th的XPath
  9. 指示函数和sign函数(符号函数)
  10. Laravel Symfony_Crawler GuzzleHttp 爬虫 抓取行政区域
  11. python实现给定列表和数值,找到列表中的两个或者多个元素和为该数值的元素下标
  12. Sublime增加GBK编码格式
  13. 安卓psp模拟器哪个好_psp模拟器安卓完美版下载_psp模拟器完美版手机版下载_玩游戏网...
  14. 一场视频号裂变活动获客3W+,头部品牌裂变案例拆解
  15. SOLIDWORKS Composer制作动画的方法
  16. JAVA计算机毕业设计中华二十四节气文化传承宣展平台Mybatis+源码+数据库+lw文档+系统+调试部署
  17. 登出/退出java_Servlet代码
  18. 方舟Mod:任何颜色集
  19. 例6-下一个更大的数
  20. 计算2个时间之间的间隔多长时间

热门文章

  1. Silverlight HTML5 Flash - RIA技术之三足鼎立
  2. 集合附加属性(HACK)
  3. 由表单中onsubmit=return false;想到的
  4. [剑指offer][JAVA]面试题第[27]题[二叉树的镜像][递归][栈]
  5. thincmf 分页无法搜索_thinkcmf5 后台搜索分页保持分页条件
  6. 1-2 三位数反转(算法竞赛入门经典)
  7. app推送以及提示音java,springboot 整合 Jpush 极光推送
  8. 2-10 [搞定!]出栈序列的合法性 (20 分)
  9. Spring开发环境搭建和第一个示例程序
  10. python点击按钮创建进程_python-创建进程的三种方式