Collecting Bugs
Time Limit: 10000MS   Memory Limit: 64000K
Total Submissions: 5394   Accepted: 2670
Case Time Limit: 2000MS   Special Judge

Description

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

Source

Northeastern Europe 2004, Northern Subregion
/*dp求期望
逆推求解
题意:(题意看题目确实比较难道,n和s都要找半天才能找到)
一个软件有s个子系统,会产生n种bug
某人一天发现一个bug,这个bug属于一个子系统,属于一个分类
每个bug属于某个子系统的概率是1/s,属于某种分类的概率是1/n
问发现n种bug,每个子系统都发现bug的天数的期望。 求解:
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);
        累加上面四项的值*概率,再加上1(下一步打到目标状态的天数)
        最后在除以(1-(i*j)/(n*s))只保留合法期望(具体为什么wo ye bu zhi dao)
整理化简便得到转移方程
*/
#include<cstdio>
#include<algorithm>
typedef double DB;
using namespace std;
const int N=;
double f[N][N];int n,s;
int main(){
while(~scanf("%d%d",&n,&s)){
f[n][s]=;
for(int i=n;~i;i--){
for(int j=s;~j;j--){
if(i==n&&j==s) continue;
f[i][j]=(i*(s-j)*f[i][j+]+
(n-i)*j*f[i+][j]+
(n-i)*(s-j)*f[i+][j+]+
n*s)/(n*s-i*j);
}
}
printf("%.4f\n",f[][]);
}
return ;
}

poj2096 Collecting Bugs[期望dp]的更多相关文章

  1. 【poj2096】Collecting Bugs 期望dp

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

  2. POJ2096 Collecting Bugs(概率DP,求期望)

    Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...

  3. POJ 2096 Collecting Bugs 期望dp

    题目链接: http://poj.org/problem?id=2096 Collecting Bugs Time Limit: 10000MSMemory Limit: 64000K 问题描述 Iv ...

  4. [POJ2096] Collecting Bugs (概率dp)

    题目链接:http://poj.org/problem?id=2096 题目大意:有n种bug,有s个子系统.每天能够发现一个bug,属于一个种类并且属于一个子系统.问你每一种bug和每一个子系统都发 ...

  5. [Poj2096]Collecting Bugs(入门期望dp)

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 6237   Accepted: 3065 ...

  6. 【POJ2096】Collecting Bugs 期望

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

  7. poj2096 Collecting Bugs(概率dp)

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

  8. POJ 2096 Collecting Bugs (概率DP,求期望)

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

  9. Poj 2096 Collecting Bugs (概率DP求期望)

    C - Collecting Bugs Time Limit:10000MS     Memory Limit:64000KB     64bit IO Format:%I64d & %I64 ...

随机推荐

  1. java.lang.OutOfMemoryError: Java heap space 解决方法

    从网上抄过来的,因为经常碰到这个问题,记录一下. java.lang.OutOfMemoryError: Java heap space 解决方法 这个问题的根源是jvm虚拟机的默认Heap大小是64 ...

  2. PHP无限极分类 - 2 - 无限极评论

    参考上一节: 结合ZUI前端框架,制作的无限极评论列表: 项目目录: 代码: <!DOCTYPE html> <html lang="en"> <he ...

  3. MongoDB · 引擎特性 · MongoDB索引原理

    MongoDB · 引擎特性 · MongoDB索引原理数据库内核月报原文链接 http://mysql.taobao.org/monthly/2018/09/06/ 为什么需要索引?当你抱怨Mong ...

  4. LIBSVM使用方法及参数设置 主要参考了一些博客以及自己使用经验。

    主要参考了一些博客以及自己使用经验.收集来觉得比较有用的. LIBSVM 数据格式需要---------------------- 决策属性  条件属性a  条件属性b  ... 2    1:7   ...

  5. selenium测试(Java)--执行JS(十八)

    1.  操作滚动条 package com.test.js; import org.openqa.selenium.By; import org.openqa.selenium.Dimension; ...

  6. 逻辑斯特回归(logistic regression)的迭代变权最小平方差算法(IRLS)

    参考资料:http://blog.csdn.net/xuanyuansen/article/details/41050507 习题: 数据及代码:  https://pan.baidu.com/s/1 ...

  7. Sublime Text 3安装清爽主题(著名的Soda Theme)

    Sublime Text是一款强大的编辑器,不但拥有众多强大的功能,还拥有很多漂亮的主题以及大量的插件可供配置使用. 本文主要描述Sublime Text 3安装清爽的主题,默认的深色主题Monoka ...

  8. CentOS查看你是否有USB 3.0端口

    近来的大多数的新计算机都有了USB 3.0接口了.但是你怎么知道你的计算机有没有USB 3.0接口?这篇短文中,我们会告诉如何在Linux下知道你的系统上有USB 3还是USB3接口. 在Linux终 ...

  9. 基于mvcpager的分页(get请求,刷新页面),提供两种样式(来自bootstrap的样式)

    使用方法:先把mvcpager.dll引用加入mvc项目 下载路径在本文末尾 前台代码 前台: @{ Layout = null; } @using Webdiyer.WebControls.Mvc ...

  10. LR通用的性能分析流程

    Step1:从分析Summary的事务执行情况入手Summary主要是判定事务的响应时间与执行情况是否合理.如果发现问题,则需要做进一步分析.通常情况下,如果事务执行情况失败或响应时间过长等,都需要做 ...