B. Collecting Bugs

Time Limit: 10000ms
Memory Limit: 64000KB

64-bit integer IO format: %lld      Java class name: Main

Special Judge
 
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

解题:概率dp,求期望逆着推。
一个软件有s个子系统,会产生n种bug
某人一天发现一个bug,这个bug属于一个子系统,属于一个分类
每个bug属于某个子系统的概率是1/s,属于某种分类的概率是1/n
问发现n种bug,每个子系统都发现bug的天数的期望。
dp[i][j]表示已经找到i种bug,j个系统的bug,达到目标状态的天数的期望
dp[n][s]=0;要求的答案是dp[0][0];
dp[i][j]可以转化成以下四种状态:
dp[i][j],发现一个bug属于已经有的i个分类和j个系统。概率为(i/n)*(j/s);
dp[i][j+1],发现一个bug属于已有的分类,不属于已有的系统.概率为 (i/n)*(1-j/s);
dp[i+1][j],发现一个bug属于已有的系统,不属于已有的分类,概率为 (1-i/n)*(j/s);
dp[i+1][j+1],发现一个bug不属于已有的系统,不属于已有的分类,概率为 (1-i/n)*(1-j/s);
整理便得到转移方程

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define LL long long
#define INF 0x3f3f3f
using namespace std;
const int maxn = ;
double dp[maxn][maxn];
int main(){
int n,s,i,j;
while(~scanf("%d%d",&n,&s)){
dp[n][s] = ;
for(i = n; i >= ; i--){
for(j = s; j >= ; j--){
if(i == n && j == s) continue;
dp[i][j]=(i*(s-j)*dp[i][j+]+(n-i)*j*dp[i+][j]+(n-i)*(s-j)*dp[i+][j+]+n*s)/(n*s-i*j);
}
}
printf("%.4f\n",dp[][]);
}
return ;
}

xtu DP Training B. Collecting Bugs的更多相关文章

  1. xtu DP Training C.炮兵阵地

    炮兵阵地 Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 11856 ...

  2. 【期望DP】[poj2096]Collecting Bugs

    偷一波翻译: 工程师可以花费一天去找出一个漏洞——这个漏洞可以是以前出现过的种类,也可能是未曾出现过的种类,同时,这个漏洞出现在每个系统的概率相同.要求得出找到n种漏洞,并且在每个系统中均发现漏洞的期 ...

  3. poj2096 Collecting Bugs(概率dp)

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

  4. Collecting Bugs poj2096 概率DP

                                                                Collecting Bugs Time Limit: 10000MS   Me ...

  5. POJ 2096 Collecting Bugs 期望dp

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

  6. poj2096 Collecting Bugs[期望dp]

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

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

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

  8. poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 3523   Accepted: 1740 ...

  9. POJ2096 Collecting Bugs(概率DP,求期望)

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

随机推荐

  1. Datapatch AND What to do if the status of a datapatch action was not SUCCESS due to finding non-ignorable errors

    1. Enterprise Manager: Starting version 12.1 Enterprise Manager now calls datapatch to complete post ...

  2. excel之实验数据处理线性拟合

    实验前准备:设计表格项,通过设计公式,从而输入原始数据后直接得到最终的结果数据,学习常用的VBA公式及处理:Cn-$B$4,其中的$B$4表示绝对单元格位置;SUM(Xm:Yn)求范围内的和. 针对实 ...

  3. 使用css3 制作switch开关

    使用css3来实现switch开关的效果: html代码: <!--switch开关--><div class="switch-btn"> <inpu ...

  4. 关于重置功能(type="reset")的相关问题

    当一个按钮具有 type="reset";的按钮是具有重置表单标签的功能的,但是当具有type="hidden"; 属性的标签的值就不会被重置,这点要留意.可以 ...

  5. android studio MQTT测试成功

    package myself.mqtt.wenzheng.studio.mqtt; import android.app.Notification; import android.app.Notifi ...

  6. git diff查看修改,出现^M换行问题

    通过命令git diff查看修改,出现^M换行问题,如图: 解决: git config --global core.whitespace cr-at-eol 换行符的问题: 提交时转换为LF,检出时 ...

  7. Tomcat7的安装与配置

    Tomcat的安装及配置我曾经使用过tomcat,并实现了一个简单的servlet程序.没想到再次安装tomcat的时候用浪费了我大半天的时间.我想有必要做个总结,否则下次不知又要花费我多少时间. 1 ...

  8. systemtap执行过程中报probe timer.profile registration error

    probe timer.profile registration error 今天在执行火焰图的过程中,代码报错,probe timer.profile registration error 经过查询 ...

  9. powerDesigner 把name项添加到注释(comment),完美方案!

    第一次写博客,分享一点经验吧,平时大家用powerDesigner的时候,pd是不会把name项默认添加到comment的,所以生成的数据库表里面也没有中文字段的注释. 我在网上查了一下.有解决方案了 ...

  10. 如何开发、本地测试、发布 Laravel 扩展包?

    如何开发.本地测试.发布 Laravel 扩展包?  Laravel/ 1年前/  4022 /  11   现在已经有了很多,关于如何开发 Laravel 扩展包的文章.但是大多文章写的太过片面,不 ...