poj2096--Collecting Bugs(可能性dp第二弹,需求预期)
Collecting Bugs
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
|
给出s个子程序。n种bug。每天能够找出一个bug,该bug是随机的一种bug,在随机的一个程序里,问当找到n种bug,而且在每一个程序中都找到过bug的期望。
dp[i][j],代表由已经在i个子程序中找到过j种bug到最后的期望,求得的dp[0][0]就是结果。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
double dp[1200][1200] ;
int main()
{
int i , j , s , n ;
scanf("%d %d", &s, &n);
memset(dp,0,sizeof(dp));
for(i = s ; i >= 0 ; i--)
{
for(j = n ; j >= 0 ; j--)
{
if( i == s && j == n ) continue ;
else if( i == s )
dp[i][j] = ( (n-j)*1.0/n*dp[i][j+1] + 1.0 ) * n / (n-j) ;
else if( j == n )
dp[i][j] = ( (s-i)*1.0/s*dp[i+1][j] + 1.0 ) * s / (s-i) ;
else
dp[i][j] = ( (s-i)*1.0*j/(s*n)*dp[i+1][j] + i*(n-j)*1.0/(s*n)*dp[i][j+1] + (s-i)*(n-j)*1.0/(s*n)*dp[i+1][j+1] + 1.0 )*s*n/(s*n-i*j);
}
}
printf("%.4lf\n", dp[0][0]);
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
poj2096--Collecting Bugs(可能性dp第二弹,需求预期)的更多相关文章
- poj2096 Collecting Bugs[期望dp]
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 5394 Accepted: 2670 ...
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
- [POJ2096] Collecting Bugs (概率dp)
题目链接:http://poj.org/problem?id=2096 题目大意:有n种bug,有s个子系统.每天能够发现一个bug,属于一个种类并且属于一个子系统.问你每一种bug和每一个子系统都发 ...
- poj2096 Collecting Bugs(概率dp)
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 1792 Accepted: 832 C ...
- [Poj2096]Collecting Bugs(入门期望dp)
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 6237 Accepted: 3065 ...
- POJ 2096 Collecting Bugs 期望dp
题目链接: http://poj.org/problem?id=2096 Collecting Bugs Time Limit: 10000MSMemory Limit: 64000K 问题描述 Iv ...
- poj 2096 Collecting Bugs 概率dp 入门经典 难度:1
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 2745 Accepted: 1345 ...
- Poj 2096 Collecting Bugs (概率DP求期望)
C - Collecting Bugs Time Limit:10000MS Memory Limit:64000KB 64bit IO Format:%I64d & %I64 ...
- 【poj2096】Collecting Bugs 期望dp
题目描述 Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other materia ...
随机推荐
- Ajax—初识
看DRP的过程.又一次学习了一遍Ajax.更深刻的体会到了Ajax所具有的魅力.Ajax是一种技术或者方法,更是一 种艺术.它让我们的程序以一种更完美的姿态呈如今用户面前.以下就让我们一起走进Ajax ...
- JS 在 HTML 无缝滚动
marquee图片无缝滚动先了解一下对象的几个的属性:innerHTML: 设置或获取位于对象起始和结束标签内的 HTMLscrollHeight: 获取对象的滚动高度.scrollLeft: 设置或 ...
- HTTP Status 500 - Request processing failed; nested exception is org.springframework.jdbc.BadSqlGram
HTTP Status 500 - Request processing failed; nested exception is org.springframework.jdbc.BadSqlGram ...
- bestcoder44#1002
这题采用分治的思想 首先,根据最后一位是否为1,将数分为两个集合, 集合与集合之间的lowbit为1, 然后将每个集合内的元素,倒数第二位是否为1,将数分为两个集合,集合与集合之间的lowbit为2 ...
- WPF MediaElement播放器2
在此问个问题,MediaElement播放本地和http上的视频没问题,但是ftp的怎么在本例中播放不了 若高手了解,请不吝赐教 using System; using System.Collecti ...
- WEB网站性能优化
最近做了一个WEB现场.幸运的是,一开始.但后来越来越慢,特别是在调试模式,,这肯定是我们的代码有问题.但是即使业务不是非常复杂的也非常慢,我们就想当然的觉得我们的代码没问题,可最后证明还是我们的代码 ...
- C#依据进程名称获取进程的句柄?
C#依据进程名称获取进程的句柄或C#怎样获取其它进程的句柄? 有时候标题名是动态变化的,所以不使用FindWindow方法! [StructLayout(LayoutKind.Sequential)] ...
- Git代理服务器设置和访问Github
因为现在工作的网络环境有着非常严格的限制,.可以说,在最近的访问通过代理Github它采取了一些曲折的.也积累了一些相关经验.我们认为有必要注意什么. 符合"不要再发明轮子"宗旨, ...
- delphi webbrowser 经常使用的演示样本
var Form : IHTMLFormElement ; D:IHTMLDocument2 ; begin with WebBrowser1 do begin D := Document as IH ...
- android弹出时间选择框
时间选择框: new DatePickerDialog(this, new OnDateSetListener() { @Override public void onDateSet(DatePick ...