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 ...
随机推荐
- 屏蔽电信流氓广告造成的诡异的问题--Android WebView 长时间不能载入页面
发如今家里的时候用Android App里的WebView打开站点非常慢,会有十几秒甚至更长时间的卡住. 可是在电脑上打开相同的网页却非常快. 查找这个问题的过程比較曲折,记录下来. 抓取Androi ...
- HDU 3315 My Brute(费用流)
职务地址:HDU 3315 这个题的思路全然是自己想出来的,自我感觉挺巧妙的. . .(大牛勿喷.. . )对大胆建图又多了一份信心. 详细思路是构造一个二分图,Si连源点.Xi连汇点,流量都是1,费 ...
- CSS背景图拉伸自适应尺寸
.bg{ background:url(images/test.jpg); filter:"progid:DXImageTransform.Microsoft.AlphaImageLoade ...
- Windows Phone开发(29):隔离存储C
原文:Windows Phone开发(29):隔离存储C 本文是隔离存储的第三节,大家先喝杯咖啡放松,今天的内容也是非常简单,我们就聊一件东东--用户设置. 当然了,可能翻译为应用程序设置合适一些,不 ...
- 修改linux系统时间、rtc时间以及时间同步
修改linux的系统时间用date -s [MMDDhhmm[[CC]YY][.ss]] 但是系统重启就会从新和硬件时钟同步. 要想永久修改系统时间,就需要如下命令:hwclock hwclock - ...
- NYOJ 709(ZZULIOJ1481) 异 形 卵
题目描写叙述 我们探索宇宙,是想了解浩瀚星空的奥妙,但我们却非常少意识到宇宙深处藏匿的危急,它们无时无刻不紧盯着我们的地球.假设外星人拜訪我们,结果可能与哥伦布当年踏足美洲大陆不会有什么两样,这是历史 ...
- error C2504: “CActiveXDocControl”: 基类没有定义
这样的错误,通常,第一个文件失败: 1.相互头包括 2.头文件秩序 此错误是编译错误,和"inclued头文件"有关 问题描写叙述 有三个头文件AgentSDK.h.AA.h.BB ...
- GPS 偏移校正(WGS-84) 至(GCJ-02) java版本号以实现
public class EvilTransform { final static double pi = 3.14159265358979324; // // // a = 6378245.0, 1 ...
- POJ 2738 Two Ends(记忆化)
Description In the two-player game "Two Ends", an even number of cards is laid out in a ro ...
- LeetCode: Multiply Strings. Java
Given two numbers represented as strings, return multiplication of the numbers as a string. Note: Th ...