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

题意:某公司请人去找程序的 bugs ,他每天可以找出一个bug 。bugs一共有 n 种,程序有 s 个子系统(0 < n, s <= 1 000)
要使每一个子系统至少有一个bug,并且所有种类的bug也至少找出一个的天数期望是多少?(精确到小数后4位) 入门概率dp:
dp[i][j] 代表的状态是有 i 种bug种类至少有一个,j 个子系统找出至少有一个bug
那么,再过一天,可能发生的情况有 4 种: (pi 指发生这种事情的概率)
找到一个已经出现过的种类的bug,并且在已经找出bug的子系统里面 P1 * dp[i][j]
找到一个未出现过的种类的bug,并且在已经找出bug的子系统里面 P2 * dp[i+1][j]
找到一个已经出现过的种类的bug,并且不在已经找出bug的子系统里面 P3 * dp[i][j+1]
找到一个是既未出现过的种类的bug,又不在已经找出bug的子系统里面 P4 * dp[i+1][j+1]
那么,就得出转移方程:
dp[i][j] = P1 * dp[i][j] + P2 * dp[i+1][j] + p3 * dp[i][j+1] + p4 * dp[i+1][j+1] + 1 (+1 是因为要过一天)
将它化简,合并掉两边的 dp[i][j]
显然 dp [n][s]=0
然后从 i = n , j = s 逆推到 i=0,j=0 dp[0][0]即为答案
 #include<stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
#define MAXN 1010 double dp[MAXN][MAXN]; int main()
{
int n,s;
while(scanf("%d%d",&n,&s)!=EOF)
{
memset(dp,,sizeof(dp));
dp[n][s]=0.0;
for (int i=n;i>=;i--)
{
for (int j=s;j>=;j--)
{
if (i==n&&j==s) continue;
dp[i][j]=(n*s+dp[i+][j]*(n-i)*j+dp[i][j+]*i*(s-j)+dp[i+][j+]*(n-i)*(s-j))/(n*s-i*j);//注意数据类型的隐式转换
}
}
printf("%.4lf\n",dp[][]);
}
return ;
}
												

Collecting Bugs (概率dp)的更多相关文章

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

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

  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,求期望)

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

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

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

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

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

  6. POJ 2096 Collecting Bugs (概率DP)

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

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

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

  8. POJ 2096 Collecting Bugs 期望dp

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

  9. poj2096 Collecting Bugs[期望dp]

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 5394   Accepted: 2670 ...

随机推荐

  1. S5PV210使用的启动方式

    2017年12月25日1. S5PV210存储配置: +内置64KB NorFlash(上电不需要初始化)(叫IROM 内部外存):用于存储预先设置的BL0; + SoC内置96KB SRAM(上电不 ...

  2. ES6里的解构赋值

    我们经常定义许多对象和数组,然后有组织地从中提取相关的信息片段.在ES6中添加了可以简化这种任务的新特性:解构.解构是一种打破数据结构,将其拆分为更小部分的过程. 一.引入背景 在ES5中,开发者们为 ...

  3. Java HashMap工作原理深入探讨

    大部分Java开发者都在使用Map,特别是HashMap.HashMap是一种简单但强大的方式去存储和获取数据.但有多少开发者知道HashMap内部如何工作呢?几天前,我阅读了java.util.Ha ...

  4. spring 配置多数据源 (案例)

    *.properties配置: <!--数据连接配置一--> jdbc.type=mysqljdbc.driver=com.mysql.jdbc.Driverjdbc.url=jdbc:m ...

  5. Windows远程CentOS桌面

    Windows远程CentOS桌面 1.VNC 服务器配置 1) 安装vncserver yum install -y vnc-server 2) 修改配置 vi /etc/sysconfig/vnc ...

  6. EffectiveJava(21)策略模式多种方式实现字符串比较

    **调用对象上的方法通常是执行该对象上的某项操作**. 如果一个对象的方法执行其他对象的操作,一个类仅仅导出这个方法(它的实例相当于一个指向该方法的指针),这样的实例被称为函数对象 例如: /** * ...

  7. Quaternion 四元数

    Quaternions are used to represent rotations. 四元数用于表示旋转. They are compact, don't suffer from gimbal l ...

  8. 内容提供器(ContentProvider)

    一.简介内容提供器(Content Provider)主要用于在不同的应用程序之间实现数据共享的功能,它提供了一套完整的机制,允许一个程序访问另一个程序中的数据,同时还能保证被访数据的安全性.目前,使 ...

  9. SQL语句练习手册--第三篇

    一.CASE的两种用法 1.1 等值判断->相当于switch case (1)具体用法模板: CASE expression WHEN value1 THEN returnvalue1 WHE ...

  10. DB2 锁问题分析与解释

    DB2 锁问题分析与解释 DB2 应用中常常会遇到锁超时与死锁现象,那么这样的现象产生的原因是什么呢.本文以试验的形式模拟锁等待.锁超时.死锁现象.并给出这些现象的根本原因. 试验环境: DB2 v9 ...