Collecting bugs
Time limit:10000 ms |
|
Memory limit:64000 K |
Total submissions:1244 |
|
Accepted:523 |
Case time limit:2000 ms |
|
Special Judge |
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 callthe 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 wocould take too long before the target cocould be reached. so Ivan and microhard agreed to use a simpler criteria --- Ivan shocould 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 wocould 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 particle 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
This is a simple question in probability DP. This is an entry question.
The questions are hard to understand. Just read them several times.
DetailsCode. Kuangbin
/* Poj 2096 probability dpwrited by kuangbindp expectation inverse recursive solution question: (the question is, is it true that N and S need to be searched for half a day) a software has s subsystems, there will be n bugs. Someone finds a bug in a day. This bug belongs to a sub-system and belongs to a classification. The probability that each bug belongs to a subsystem is 1/s, the probability of a classification is that 1/N queries discover n kinds of bugs, and each subsystem is expected to discover the number of days of the bug. Solution: DP [I] [J] indicates that the I-type bug has been found. The J-system bug indicates the expected DP [N] [s] = 0 for the number of days to reach the target State; the answer is DP [0] [0]; DP [I] [J] can be converted to the following four States: DP [I] [J], A bug is found to belong to the existing I classification and J systems. The probability is (I/n) * (J/s); DP [I] [J + 1]. It is found that a bug belongs to an existing category and does not belong to an existing system. the probability is (I/n) * (1-j/s); DP [I + 1] [J]. It is found that a bug belongs to an existing system and does not belong to an existing category, the probability is (1-I/n) * (J/s); DP [I + 1] [J + 1], and a bug is found not to belong to an existing system, does not belong to an existing classification. The probability is (1-I/n) * (1-j/s ). */ # Include <Stdio. h> # Include <Iostream> # Include <Algorithm># Include < String . H> Using Namespace STD; Const Int Maxn = 1010 ; Double DP [maxn] [maxn]; Int Main (){ Int N, S; While (Scanf (" % D " , & N, & S )! = EOF) {DP [N] [s] = 0 ; For ( Int I = N; I> = 0 ; I -- ) For ( Int J = s; j> = 0 ; J -- ){ If (I = N & J = s) Continue ; DP [I] [J] = (I * (S-j) * DP [I] [J + 1 ] + (N-I) * j * DP [I + 1 ] [J] + (n-I) * (S-j) * DP [I + 1 ] [J + 1 ] + N * s)/(n * s-I * J);} printf ( " %. 4lf \ n " , DP [ 0 ] [ 0 ]);// Change g ++ on poj to %. 4f. } Return 0 ;}