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 ...
随机推荐
- 最牛B的编程套路
最近,我大量阅读了Steve Yegge的文章.其中有一篇叫“Practicing Programming”(练习编程),写成于2005年,读后令我惊讶不已: 与你所相信的恰恰相反,单纯地每天埋头于工 ...
- 去掉windows文件末尾的^M: %s/\r//g
去掉windows文件末尾的^M: %s/\r//g
- Socket编程实践(12) --UDP编程基础
UDP特点 无连接,面向数据报(基于消息,不会粘包)的传输数据服务; 不可靠(可能会丢包, 乱序, 反复), 但因此普通情况下UDP更加高效; UDP客户/服务器模型 UDP-API使用 #inclu ...
- 一个简单而经典的RTX51 Tiny应用实例
关于RTX51 Tiny嵌入式实时操作系统的描写叙述请參考本人的上一篇博文(RTX51 Tiny实时操作系统学习笔记-初识RTX51 Tiny). 本篇博文.我将通过一个实例代码,带大家深入了解一下R ...
- javaEE jdbc编程步骤
1.载入数据库驱动(jar文件) //须要下载一个数据库的jar包,并导入对应的JDBC项目中,创建路径! Class.forName("com.mysql.jdbc.Driver" ...
- android ksoap2调用.net Webservice 方法总结
android ksoap2调用.net Webservice 方法直接放到一个类里: package com.util; import org.ksoap2.SoapEnvelope; impor ...
- Follow your hear(跟着心走)
端午三天的哈尔滨之旅已经over,非常开心真的非常开心.听了刘四风老师的"为爱开讲.我爱这世界"的论坛,尽管.这三天老师讲的不多.可是句句是精华.Follow your heart ...
- 大爱jQuery,10美女模特有用jQuery/CSS3插入(集成点免费下载)
整合下载地址:http://download.csdn.net/detail/yangwei19680827/7343001 jQuery真的是一款非常犀利的Javascript框架,利用jQuery ...
- 【NOIP2002】矩形覆盖 DFS
首先,我喜欢愤怒搜索,因为尽管说K<=4,的确K小于或等于3的. 当然某些K<=3还600ms的我就不加评论了. 好吧,可是怎么搜呢?我们考虑到矩形数量非常少,所以能够怒搜矩形. 一些神做 ...
- 【迷你微信】基于MINA、Hibernate、Spring、Protobuf的即时聊天系统:3.技术简介之MinaFilter——LoggingFilter (转)
欢迎阅读我的开源项目<迷你微信>服务器与<迷你微信>客户端 LoggingFilter 接下来,使我们对Filter介绍的最后一个——LoggingFilter. 与Proto ...