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. N++ 道ASP.NET面试题

    InterviewQuestions-ASP.NET N++ 道ASP.NET面试题 1. 简述 private. protected. public. internal 修饰符的访问权限. 答 . ...

  2. C源程序到可执行文件的四个过程

    C源程序到可执行文件的四个过程 1.预处理:预编译器执行.譬如C中的宏定义就是由预编译器处理,注释等也是由预编译器处理的 gcc -E -hello.c -o hello.i 2.编译:编译器来执行. ...

  3. ITIL,是否已是昨日黄花

    首先声明自己不是ITIL方面的专家,特别是具体的规范细节,后面论述如有不当,请指正.但我为什么会提起它?主要是因为它和运维(IT服务管理)相关性太大了.早起的运维完全就是以ITIL来蓝本构建的,在当时 ...

  4. EffectiveJava(5)避免创建不必要的对象

    避免创建不必要的对象 1.通过延迟初始化对象提高性能 调用功能方法时调用静态工厂方法,而不是调用类时使用 2.适配器:把功能委托给一个后备对象,从而为后备对象提供一个接口的对象 3.自动装箱:优先使用 ...

  5. http接口测试—自动化测试框架设计

    转载:https://my.oschina.net/hellotest/blog/499719 一.测试需求描述 对服务后台一系列的http接口功能测试. 输入:根据接口描述构造不同的参数输入值(Js ...

  6. 函数传参,改变Div任意属性的值&&图片列表:鼠标移入/移出改变图片透明度

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. 【Nginx】HTTP配置模型

    当Nginx检測到配置文件里存在配置块http{}时.会建立一个ngx_http_conf_ctx_t结构体,该结构体定义例如以下: typedef struct { void **main_conf ...

  8. android 通过bitmapfactory得到图片真实像素的方法,以及没有得到真实像素的原因

    原文来自:原文地址 由于这个错误导致浪费非常长时间找原因,所以要赶紧记录下来. 过程是这种,在使用android读取图片的时候,就是使用BitmapFactory.decodeResource(thi ...

  9. 苹果版小黄车(ofo)app主页菜单效果

    代码地址如下:http://www.demodashi.com/demo/12823.html 前言: 最近又是公司项目上线一段时间了,又是到了程序汪整理代码的节奏了.刚好也用到了ofo主页菜单的效果 ...

  10. linux vi设置行号

    首先,vi的配置文件是/etc/vim/vimrc,不同系统可能有出入,不过我建议大家在home中建立一个.vimrc文件,照样可以达到同样的效果.其实/etc中的配置是全局的,home中的配置只针对 ...