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. SQL Server索引 (原理、存储)聚集索引、非聚集索引、堆 <第一篇>

    一.存储结构 在SQL Server中,有许多不同的可用排列规则选项. 二进制:按字符的数字表示形式排序(ASCII码中,用数字32表示空格,用68表示字母"D").因为所有内容都 ...

  2. HDU 1754

    成段更新 easy #include <stdio.h> #include <string.h> #include <math.h> #include <io ...

  3. [转载] 一些非常好的 linux 基础工具

    http://linuxtools-rst.readthedocs.org/zh_CN/latest/index.html 作者整理的非常好, 需要的时候可以拿来参考

  4. 一些比较好的shellscript脚本

    1. 变量与替换 #!/bin/bash # 变量替换 # 另外, 变量替换还有许多别的语法 # 例如, b=${a/23/bb} 将 23 替换成 bb 等等, 用到时再找 a=375 hello= ...

  5. Python学习(8)字符串

    目录 Python 字符串 Python 访问字符串中的值 Python 字符串更新 Python 转义字符 Python 字符串运算符 Python 字符串格式化 Python 三引号 Unicod ...

  6. (二)ubuntu学习前传—uboot常见命令

    1.uboot命令类似于linux行缓冲命令行,当我们向终端命令行输入命令的时候,这些命令没有立即被系统识别,而是被缓冲到一个缓存区(也就是系统认为我换没有输入完),当我们按下回车键(换行)后,系统就 ...

  7. TortoiseSvn

    TortoiseSVN 是svn版本控制系统的一个免费开源客户端,它是svn版本控制的 Windows 扩展.可以使你避免使用枯燥而且不方便的命令行.它完全嵌入 Windows Explorer,使用 ...

  8. Delphi 过程与函数

    注:该内容整理自以下链接. http://chanlei001.blog.163.com/blog/static/340306642011111615445266/ delphi 过程以保留字proc ...

  9. android实现系统电话通话过程中自动感应黑屏

    package com.developmenttools.customui.activity; import java.util.HashSet;import java.util.Set; impor ...

  10. Android 图片Exif信息相关的获取与修改

    1 Exif是什么 Exif是一种图像文件格式,它的数据存储于JPEG格式是完全相同的,实际上Exif格式就是JPEG格式头插入了 数码照片的信息,包括拍摄的光圈.快门.平衡白.ISO.焦距.日期时间 ...