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 ( < n, s <=  ).

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

 

Sample Output

3.0000

Source

Northeastern Europe 2004, Northern Subregion
 
dp求期望
逆着递推求解
题意:(题意看题目确实比较难道,n和s都要找半天才能找到)
一个软件有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>
using namespace std;
#define N 1006
#define S 1006
int n,s;
double dp[N][S]; /*
dp[i][j]表示已经找了i个bug,j个子系统的期望
dp[n][s]=0;
目标状态为dp[0][0] dp[i][j]转化为下列4个状态
dp[i][j]的时候,表示找到的bug属于i个bug和j个系统之中,则概率为(i/n)*(j/s)
dp[i][j+1]的时候,表示找到的bug属于i个bug,但是不属于j个系统,则概率为(i/n)*(1-j/s)
dp[i+1][j]的时候,表示找到的bug属于j个系统的,但是不属于i个bug里面的,则概率为(1-i/n)*(j/s)
dp[i+1][j+1]的时候,表示找到的bug既不属于i个bug的,也不属于j个系统的,则概率为(1-i/n)*(1-j/s)
*/ int main()
{
while(scanf("%d%d",&n,&s)==){
memset(dp,,sizeof(dp));
dp[n][s]=;
for(int i=n;i>=;i--){
for(int j=s;j>=;j--){
if(i==n && j==s) continue;
double p1=i*1.0*(s-j)/n/s;
double p2=(n-i)*j*1.0/n/s;
double p3=(n-i)*(s-j)*1.0/n/s;
double p0=-i*j*1.0/n/s; dp[i][j]=p1*dp[i][j+]+p2*dp[i+][j]+p3*dp[i+][j+]+;
dp[i][j]/=p0; }
}
printf("%lf\n",dp[][]);
}
return ;
}

poj 2096 Collecting Bugs(期望 dp 概率 推导 分类讨论)的更多相关文章

  1. POJ 2096 Collecting Bugs 期望dp

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

  2. POJ 2096 Collecting Bugs (概率DP,求期望)

    Ivan is fond of collecting. Unlike other people who collect post stamps, coins or other material stu ...

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

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

  4. Poj 2096 Collecting Bugs (概率DP求期望)

    C - Collecting Bugs Time Limit:10000MS     Memory Limit:64000KB     64bit IO Format:%I64d & %I64 ...

  5. POJ 2096 Collecting Bugs:期望dp

    题目链接:http://poj.org/problem?id=2096 题意: 有一个程序猿,他每天都会发现一个bug. bug共有n个种类.属于某一个种类的概率为1/n. 有s个子系统,每个bug属 ...

  6. poj 2096 Collecting Bugs && ZOJ 3329 One Person Game && hdu 4035 Maze——期望DP

    poj 2096 题目:http://poj.org/problem?id=2096 f[ i ][ j ] 表示收集了 i 个 n 的那个. j 个 s 的那个的期望步数. #include< ...

  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

    Collecting Bugs Time Limit: 10000MS   Memory Limit: 64000K Total Submissions: 1716   Accepted: 783 C ...

  9. poj2096 Collecting Bugs[期望dp]

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

随机推荐

  1. poj 3176 Cow Bowling(dp基础)

    Description The cows don't use actual bowling balls when they go bowling. They each take a number (i ...

  2. 操作系统——IO缓存技术

    一.为什么引入缓存技术 为了解决cpu速度和外部设备速度不匹配的问题. 降低了io对cpu的中断的次数.每进行一次IO设备的时间都非常长,所以把数据先放入缓冲区,再进行IO操作. 二.缓冲技术的实现 ...

  3. 【InversionCount 逆序对数 + MergeSort】

    Definition of Inversion: Let (A[0], A[1] ... A[n], n <= 50) be a sequence of n numbers. If i < ...

  4. [转载]C#开源项目(国外的还是很多)

    C#开源项目(国外的还是很多)一.Ajax框架Ajax.NET Professional (AjaxPro)是最先把AJAX技术在微软.NET环境下的实现的AJAX框架之一.它在客户端脚本之上创建代理 ...

  5. 未能加载文件或程序集“System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35”

    最近用vs2012发布程序,然后将更新后的程序文件部署到服务器上,由于服务器上本来有此系统,所以只更新了修改的文件 . 进行系统登录时提示:未能加载文件或程序集“System.Web.Extensio ...

  6. js获取当前页面的网址域名地址

    1.获取当前完整网址thisURL = document.URL;thisHREF = document.location.href;thisSLoc = self.location.href;thi ...

  7. Oracle instr 及 like

    原文: http://www.cnblogs.com/crazyjava/archive/2012/10/31/2748202.html instr(string1,string2[,start_po ...

  8. Parser Error Message: Access is denied【转】

    PRB: Access Denied Error When You Make Code Modifications with Index Services Running View products ...

  9. iOS 8以上的设置的跳转

    iOS8以上的系统应用可以与设置进行深层的交互,用户可以根据APP的需要进行对应的权限的设置. 现在大多数的APP依旧仅仅是弹出一个包含操作指令的警示窗口,如“进入设置>隐私>位置> ...

  10. CSS注意事项

    1.定义样式不能就加:隔开 当有定义的css样式并没有起作用的时候看看定义该样式前边有没有加“;”的如 p{};div{}