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. android studio 编译sdk版降低报错解决方法

    解决办法如下: 步骤1:在gradle中修改 compile sdk 版本,比如 8. 步骤2:在gradle中删除v7包的依赖 步骤3:在manifest中修改theme,supportsRtl.t ...

  2. vue中清除定时器

    1.data中定义 timer:90,timeName:null 点击支付则倒计时按钮出来 pay(){ this.timeName= setInterval(()=>{ this.timer- ...

  3. PO模型

    大神绕道而行,自我小白的笔记,仅此 一.创建文件夹,创建xxx.ini文件用来存放界面的定位元素,用 [界面_element]-->界面, 来划分界面界面元素,维护方便.定位元素的格式:  us ...

  4. a标签下载;页面传参row对象先转换成字符串。

    jsp:添加一列 <th data-options="field:'id',width:180,formatter: rowformater" width="20% ...

  5. SSM框架-SpringMVC 实例文件上传下载

    一.新建一个Web工程,导入相关的包 springmvc的包+commons-fileupload.jar+connom-io.jar+commons-logging,jar+jstl.jar+sta ...

  6. vue搭建环境并创建项目

    1.>npm install @vue/cli -g 2.创建项目A a.>vue ui b.在弹出的管理界面创建项目 或 a.npm install -g @vue/cli-init b ...

  7. STL之Queue容器

    1.Queue容器 1)queue是队列容器,是一种“先进先出”的容器. 2)queue是简单地装饰deque容器而成为另外的一种容器. 3)头文件.#include <queue> 2. ...

  8. eclipse maven install没反应解决办法

    .打开eclipse的Window菜单-->java-->Installed JREs .点击用的jdk,edit,在Default VM arguments里面填入-Dmaven.mul ...

  9. 城市里的间谍B901

    城市里的间谍   城市里的间谍 难度级别:C: 运行时间限制:1000ms: 运行空间限制:51200KB: 代码长度限制:2000000B 试题描述 某城市的地铁是线性的,有 n(2 <= n ...

  10. 【2017-2-19】C#数据类型,数据转换,变量,常量,转义符

    数据类型 一.基本数据类型 1.值类型(不可以为null) ⑴整型(可以为负数) byle,int,short,long(从小到大排列) 常用整型 int a=值(小于10位数) long b=值(1 ...