Collecting Bugs
Time Limit: 10000MS   Memory Limit: 64000K
Total Submissions: 3064   Accepted: 1505
Case Time Limit: 2000MS   Special Judge

Description

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

Source

Northeastern Europe 2004, Northern Subregion
 
概率dp
期望问题
d[i][j]表示已收集到i个bugs(category中)和j个bugs(subsystem中)到完成时还需要的时间。
现找到一个bug,有四种可能:
1.new       new
2.new      old
3.old       new
4.old      old
状态转移方程为:
d[i][j] = ((n - i) / n) * ((s - j) / s) * (d[i + 1][j + 1] + 1) + ((n - i) / n) * (j / s) * (d[i + 1][j] + 1) + (i / n) * ((s - j) / s) * (d[i][j + 1] + 1) +  (i / n) * (j / s) * (d[i][j] + 1);
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
using namespace std;
#define ll long long
#define _cle(m, a) memset(m, a, sizeof(m))
#define repu(i, a, b) for(int i = a; i < b; i++)
#define MAXN 1005 double d[MAXN][MAXN];
int main()
{
int n, s;
while(~scanf("%d%d", &n, &s))
{
_cle(d, );
for(int i = n; i >= ; i--)
for(int j = s; j >= ; j--) {
if(i == n && j == s) ;
else {
d[i][j] = ((d[i + ][j + ] + 1.0) * (double)((n - i) * (s - j))
+ (d[i + ][j] + 1.0) * (double)((n - i) * (j))
+ (d[i][j + ] + 1.0) * (double)((i) * (s - j))
+ i * j) / (double)(n * s - i * j);
}
}
printf("%.4lf\n", d[][]);
}
return ;
}

Collecting Bugs(POJ 2096)的更多相关文章

  1. poj2096 Collecting Bugs(概率dp)

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 1792   Accepted: 832 C ...

  2. 【POJ】2096 Collecting Bugs(数学期望)

    题目 传送门:QWQ 分析 数学期望 用$ dp[i][j] $表示发现了在$ j $个子系统里面发现了$ i $个bug到$ s $个子系统里面发现了$ n $个bug需要的期望天数. $ dp[0 ...

  3. POJ - 2096 Collecting Bugs(概率dp)

    https://vjudge.net/problem/POJ-2096 题意 一个软件有s个子系统,会产生n种bug.某人一天发现一个bug,这个bug属于某种bug,发生在某个子系统中.求找到所有的 ...

  4. poj 2096 Collecting Bugs(期望 dp 概率 推导 分类讨论)

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

  5. [Poj2096]Collecting Bugs(入门期望dp)

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 6237   Accepted: 3065 ...

  6. 01背包问题:Charm Bracelet (POJ 3624)(外加一个常数的优化)

    Charm Bracelet    POJ 3624 就是一道典型的01背包问题: #include<iostream> #include<stdio.h> #include& ...

  7. Scout YYF I(POJ 3744)

    Scout YYF I Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5565   Accepted: 1553 Descr ...

  8. 广大暑假训练1(poj 2488) A Knight's Journey 解题报告

    题目链接:http://vjudge.net/contest/view.action?cid=51369#problem/A   (A - Children of the Candy Corn) ht ...

  9. Games:取石子游戏(POJ 1067)

    取石子游戏 Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 37662   Accepted: 12594 Descripti ...

随机推荐

  1. autofs实现nfs自动挂载

    apt-get install autofs 主配置文件/etc/auto.master 副配置文件可以在之配置文件中自定义 能生效的配置文件如下例: 将/usr/local/nginx/html挂载 ...

  2. NoSQL数据库:数据的一致性

    NoSQL数据库:数据的一致性 读取一致性 强一致性 在任何时间访问集群中任一结点,得到的数据结果一致: 用户一致性 对同一用户,访问集群期间得到的数据一致: 解决用户一致性:使用粘性会话,将会话绑定 ...

  3. JAVA中在Myeclipse里把表导入成相应的poco实体类

    参考:地址: http://blog.csdn.net/jintaiyong/article/details/7383982

  4. 《易货》Alpha版本发布说明

    一.引言 本说明描述了校淘1.0版本的已经实现的主要功能,对运行环境的要求,以及目前软件所具有的一些问题和限制. 二.主要功能 本软件面向的是在校大学生,方便大学生将自己闲置的物品以二手商品的形式发布 ...

  5. ZOJ-2362 Beloved Sons 最大权值匹配

    题意:国王有N个儿子,现在每个儿子结婚都能够获得一定的喜悦值,王子编号为1-N,有N个女孩的编号同样为1-N,每个王子心中都有心仪的女孩,现在问如果安排,能够使得题中给定的式子和最大. 分析:其实题目 ...

  6. openstack 网卡

    桥接基本原理: 物理网卡eth0 br0(桥) tap0,tap1(tap是给vm使用的接口)

  7. 初识redis——mac下搭建redis环境

    一.redis简介 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合)和zset(有 ...

  8. 关于json 的那些知识点

    深入理解JSON对象 前面的话 json(javascript object notation)全称是javascript对象表示法,它是一种数据交换的文本格式,而不是一种编程语言,用于读取结构化数据 ...

  9. view的封装

    如果一个view内部的子控件比较多,一般会考虑自定义一个view,把它内部子控件的创建屏蔽起来,不让外界关心 外界可以传入对应的模型数据给view,view拿到模型数据后给内部的子控件设置对应的数据 ...

  10. C#_接口

    .Net提供了接口,这个不同于Class或者Struct的类型定义.接口有些情况,看似和抽象类一样,因此有些人认为在.Net可以完全用接口来替换抽象类.其实不然,接口和抽象类各有长处和缺陷,因此往往在 ...