Collecting Bugs
Time Limit: 10000MS   Memory Limit: 64000K
Total Submissions: 3523   Accepted: 1740
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. 1 2

Sample Output

3.0000

题意:一个软件有S个系统。但会产生N种bug。一个人一天能够发现一个bug,这个bug既属于某一个系统。又属于某一个分类。每一个bug属于某个系统的概率是1/S,属于某种分类的概率是1/N。如今问你发现N种bug且S个系统都发现bug的天数的期望。

思路:用dp[i][j]表示发现i种bug且j个系统都发现bug的天数的期望。能够得到4种状态

1。dp[i][j]—— 新bug  既属于已发现bug的种类。又属于已经发现bug的系统。则有概率 (i / S) * (j / N)

2。dp[i+1][j]—— 新bug  不属于已发现bug的种类,属于已经发现bug的系统。则有概率 (1 - i / N) * (j / S)

3。dp[i][j+1]—— 新bug  属于已发现bug的种类,不属于已经发现bug的系统。则有概率 (i / N) * (1 - j / S)

4,dp[i+1][j+1]—— 新bug 既不属于已经发现bug的种类,也不属于已经发现bug的系统。

则有概率 (1 - i / N) * (1 - j / S)

求期望倒着递推,由dp[N][S] = 0 退出 dp[0][0]就可以。注意推导时 全是浮点型。

AC代码:

  1. #include <cstdio>
  2. #include <cstring>
  3. #include <algorithm>
  4. using namespace std;
  5. double dp[1010][1010];
  6. int main()
  7. {
  8. int N, S;
  9. while(scanf("%d%d", &N, &S) != EOF)
  10. {
  11. memset(dp, 0, sizeof(dp));
  12. for(int i = N; i >= 0; i--)
  13. {
  14. for(int j = S; j >= 0; j--)
  15. {
  16. if(i == N && j == S) continue;
  17. double x = i, y = j;
  18. double p1 = dp[i+1][j] * (y / S) * (1 - x / N);
  19. double p2 = dp[i][j+1] * (x / N) * (1 - y / S);
  20. double p3 = dp[i+1][j+1] * (1 - y / S) * (1 - x / N);
  21. double p0 = 1 - (x / N) * (y / S);
  22. dp[i][j] = (p1 + p2 + p3 + 1) / p0;
  23. }
  24. }
  25. printf("%.4lf\n", dp[0][0]);
  26. }
  27. return 0;
  28. }

poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】的更多相关文章

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

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

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

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

  3. poj 2096 Collecting Bugs 概率dp 入门经典 难度:1

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 2745   Accepted: 1345 ...

  4. poj 2096 Collecting Bugs (概率dp 天数期望)

    题目链接 题意: 一个人受雇于某公司要找出某个软件的bugs和subcomponents,这个软件一共有n个bugs和s个subcomponents,每次他都能同时随机发现1个bug和1个subcom ...

  5. POJ 2096 Collecting Bugs (概率DP)

    题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...

  6. poj 2096 Collecting Bugs - 概率与期望 - 动态规划

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

  7. poj 3744 Scout YYF I(递推求期望)

    poj 3744 Scout YYF I(递推求期望) 题链 题意:给出n个坑,一个人可能以p的概率一步一步地走,或者以1-p的概率跳过前面一步,问这个人安全通过的概率 解法: 递推式: 对于每个坑, ...

  8. POJ 2096 Collecting Bugs 期望dp

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

  9. poj 2096 Collecting Bugs(期望 dp 概率 推导 分类讨论)

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

随机推荐

  1. android studio 按钮运行按钮后,不弹出选择运行模拟器的对话框

    这个问题实际上很简单,奈何碰到的时候做了很多无用功.clean,rebulid... 特此记录,方便后来人. 解决步骤: 1.关闭AndroidStudio,并重启. 2. 把截图中的地方的勾去掉.检 ...

  2. 关于超大binlog事件的问题

    我手里维护了一个项目,其功能是用Java模拟一个MariaDB的slave库连接到主库,对从主库传输过来的binlog事件进行监听与分析 碰到一个问题是: 如果主库做了一个很大的修改操作(比方说直接d ...

  3. Cryptography I 学习笔记 --- 总结

    在b站上大概的看完了Dan Boneh的密码学,对现代密码学总算有了一个粗浅的认识. 总算能在纸上手写RSA公式并且证明之了,蛤蛤. 总体的感触就是,现代密码学是一个非常博大精深的体系,我等程序员最重 ...

  4. 为Zepto添加Slide动画效果

    一.缘由 公司的移动端项目,采用zepto为主要框架,但是zepto毕竟是精简版的jquery,体积小了,功能自然没有这么强大,特别是动画和选择器这两块,需要我们自己去拓展. 在项目开发过程中,很多页 ...

  5. JAVAWEB开发之JSP、EL、及会话技术(Cookie和Session)的使用详解

    Servlet的缺点 开发人员要十分熟悉JAVA 不利于页面调试和维护(修改,重新编译) 很难利用网页设计工具进行页面设计(HTML内容导入到servlet中,用PrintWriter的对象进行输出) ...

  6. 2017.2.13 开涛shiro教程-第十二章-与Spring集成(二)shiro权限注解

    原博客地址:http://jinnianshilongnian.iteye.com/blog/2018398 根据下载的pdf学习. 第十二章-与Spring集成(二)shiro权限注解 shiro注 ...

  7. 取消sudo的密码

    终端输入sudo visudo,显示为以下内容: 我们只要修改其中的一点内容,就可以实现sudo不需要输入密码了 sudo su -chmod +w /etc/sudoersvim /etc/sudo ...

  8. linux暴力密码破解工具hydra安装与使用

    说明:hydra是著名黑客组织thc的一款开源的暴力密码破解工具,可以在线破解多种密码.官网:http://www.thc.org/thc-hydra,可支持AFP, Cisco AAA, Cisco ...

  9. Linux系统编程_1_文件夹读取(实现简单ls命令)

    闲来无事.随便写写,实现简单的ls命令: | 1 #include <stdio.h> | 2 #include <stdlib.h> | 3 #include <dir ...

  10. [C++设计模式] state 状态模式

    <head first 设计模式>中的样例非常不错,想制造一个自己主动交易的糖果机,糖果机有四个状态:投入钱不足,投入钱足够,出售糖果,糖果售罄. 糖果机的当前状态处于当中不同的状态时,它 ...