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

  题目大意 有n台电脑,每台电脑都有s种bug,每天等概率在一台电脑中发现一个bug,问所有电脑中至少发现了1种bug,并且所有种bug都被发现期望下需要的天数。

  用 dp[i][j] 表示在i台电脑中发现了bug,有j种bug被发现到最终状态期望要的天数。

  讨论下面几种情况

  1)下一次在新的一台电脑上发现了新的一种bug,由 f[i + ][j + ] 转移过来

  2)下一次在新的一台电脑上没有发现新的一种bug,由 f[i + ][j] 转移过来

  3)下一次没有在新的一台电脑上发现了新的一种bug,由 f[i][j + ] 转移过来

  4)下一次没有在新的一台电脑上没有发现新的一种bug,由 f[i][j] 转移过来

  因此列得方程

  整理得到转移方程。

Code

 /**
* poj
* Problem#2096
* Accepted
* Time: 157ms
* Memory: 8648k
*/
#include <iostream>
#include <cstdio>
using namespace std; int n, s;
double f[][]; inline void init() {
scanf("%d%d", &n, &s);
} inline void solve() {
int ns = n * s; f[n][s] = ;
for(int i = n; ~i; i--)
for(int j = s; ~j; j--)
if(i < n || j < s)
f[i][j] = (f[i + ][j] * (n - i) * j + f[i][j + ] * i * (s - j) + f[i + ][j + ] * (n - i) * (s - j) + ns) / (ns - i * j); printf("%.4lf", f[][]);
} int main() {
init();
solve();
return ;
}

poj 2096 Collecting Bugs - 概率与期望 - 动态规划的更多相关文章

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

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

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

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

  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 期望dp

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

  7. poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 3523   Accepted: 1740 ...

  8. poj 2096 Collecting Bugs && ZOJ 3329 One Person Game && hdu 4035 Maze——期望DP

    poj 2096 题目:http://poj.org/problem?id=2096 f[ i ][ j ] 表示收集了 i 个 n 的那个. j 个 s 的那个的期望步数. #include< ...

  9. POJ 2096 Collecting Bugs

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 1716   Accepted: 783 C ...

随机推荐

  1. 解读经典面试题for循环console.log

    for (var i = 1; i <= 5; i++) { setTimeout(function () { console.log(i) },1000)} 会打印出5个6,这是why 因为 ...

  2. php 下载完成后删除文件

    最近遇到一个需求:下载用户上传的图片,但是图片不断更新. 1.需要将图片从图片服务器下载到网站后台服务器 2.压缩文件夹生成zip压缩包 3.下载压缩包 4.删除压缩包和临时文件夹 其中遇到了一个问题 ...

  3. 《linux就该这么学》找到一本不错的Linux电子书,《Linux就该这么学》。

    本帖不是广告贴,只是感觉有好的工具书而已 本书是由全国多名红帽架构师(RHCA)基于最新Linux系统共同编写的高质量Linux技术自学教程,极其适合用于Linux技术入门教程或讲课辅助教材,目前是国 ...

  4. 不用ajax实现异步请求:XmlHttpRequest 小记

    视图页面代码 控制器代码

  5. 关于hibernate总是报错 配置factory的id找不到,mapping配置文件Could not parse mapping document from input stream

    Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from input stream ...

  6. 在TensorFlow中运行程序多次报错:AttributeError: __exit__

    我没有记住语句 with tf.Session() as sess: 多次写成了 with tf.Session as sess: 吃括号这个低级的错误又犯了,真不应该,立下flag:以后再犯相同的错 ...

  7. 键值对Dictionary、KeyValuePair、Hashtable 简单使用。

    KeyValuePair是单个的键值对对象.KeyValuePair可用于接收combox选定的值. 例如:KeyValuePair<string, object> par = (KeyV ...

  8. 模拟QQ登录

    2018-10-28 15:54:38 开始写 import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.bor ...

  9. 【2017-03-02】C#函数,递归法

    函数 函数的意义:独立完成某项功能的个体 函数的优势:1.提高代码的重用性     2.提高功能开发的效率   3.提高程序代码的可维护性 函数四要素: 1,输入:(值的类型+名称) 2,输出:ret ...

  10. Linux基础命令---chsh

    chsh 改变用户登录时使用的shell,默认使用bash.如果命令行上没有给出shell,chsh将提示输入一个shell.chsh将接受系统上任何可执行文件的完整路径名.但是,如果shell未在“ ...