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. 微博(MicroBlog)

    ylbtech_Miscellaneos  Inner 新浪微博  www.weibo.com 搜狐微博 http://t.sohu.com 网易微博 http://t.163.com/session ...

  2. django开发环境部署之pip、virtualenv、virtualenvwrapper

    step1:安装pip 在python中可以使用easy_install和pip安装python拓展但推荐使用pip Don't use easy_install, unless you like s ...

  3. django book多站点学习

    多个站点 Django 的多站点系统是一种通用框架,它让你可以在同一个数据库和同一个Django项目下操作多个网站. 这是一个抽象概念,理解起来可能有点困难,因此我们从几个让它能派上用场的实际情景入手 ...

  4. ES6里的修饰器Decorator

    修饰器(Decorator)是一个函数,用来修改类的行为. 一.概述 ES6 引入了这项功能,目前 Babel 转码器已经支持Decorator 首先,安装babel-core和babel-plugi ...

  5. P6 EPPM 安装和配置指南

    In This Section Installation and Configuration Guide Manual Installation Guides P6 Professional Inst ...

  6. Mybaits的特点及优点

    1.SQL语句和代码分离 便于统一管理和维护,不必再Java代码中调式SQL语句.但是当SQL语句出错时,控制台不会打印Log, 解决办法--引用log4j 2.用标签拼接SQL语句 用标签代替JAV ...

  7. Sending SMS And Dialing Numbers without User Consent(Context is not needed)

    Sending SMS And Dialing Numbers without User Consent Sending SMS does not require context or user in ...

  8. 黑马程序猿——JAVA高新技术——反射

    ----------android培训.java培训.java学习型技术博客.期待与您交流!------------ 一.对于反射的概念 对于JAVA反射机制是在执行状态中,对于随意一个类.都可以知道 ...

  9. block传值以及利用block封装一个网络请求类

    1.block在俩个UIViewController间传值 近期刚学了几招block 的高级使用方法,事实上就是利用block语法在俩个UIViewController之间传值,在这里分享给刚開始学习 ...

  10. 【MVC5】使用Autofac实现依赖注入

    1.安装Autofac 在Package Manager Console执行如下命令: Install-Package AutofacInstall-Package Autofac.Mvc5 2.追加 ...