"POJ2096" Collecting Bugsdescriptionivan 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 with all bugs categories, he calls the program disgusting, publishes this spreadsheet on his home page, an D forgets completely about the program.
Companies, Macrosoft and Microhard is in tight competition. Microhard wants to decrease sales of one Macrosoft program. They hire Ivan to prove, the program in question is disgusting. However, Ivan has a complicated problem. This new program have S subcomponents, and finding bugs of all types in each subcomponent would take too long before the TA Rget could be reached. So Ivan and Microhard agreed to use a simpler criteria---Ivan should find at least one bugs in each subsystem and at LEAs T one bug of each category.
Macrosoft knows about these plans and it wants to estimate the time that's required for Ivan to call their program Disgusti Ng. It's important because the company releases a new version of soon, so it can correct its plans and release it quicker. Nobody would is interested in Ivan's opinion about the reliability of the obsolete version.
A Bug found in the program can is of any category with equal probability. Similarly, the bug can be found in any given subsystem with equal probability. Any particular bugs cannot belong to the different categories or happen simultaneously in both different subsystems. The number of bugs in the program was almost infinite, so the probability of finding a new bug of some category in some sub System does not reduce after finding any number of bugs of the that category in the that subsystem.
Find an average time (in days of Ivan's work) required to name the program disgusting. Inputinput file contains the integer numbers, N and s (0 < N, s <= 1 000). Outputoutput 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
Test Instructions : There are n kinds of bug,s systems, each day to find 1 systems of 1 bugs, assuming that the number of each bug is infinitely many (every time a bug is found to be the probability of 1/n), asked to find each bug and each system found the number of days of expected bug.
FIX: Set F[I][J] for the number of days that I have been found in J systems, the equation is obviously
F[I][J]=F[I+1][J+1]*P1+F[I+1][J]*P2+F[I][J+1]*P3+F[I][J]*P4 (P1,P2,P3,P4 is what I don't have to say anymore)
Found on both sides of the equal sign f[i][j], move items can be
#include <cstdio>#include<cmath>#include<iostream>using namespacestd;intn,s;Doublef[1010][1010];intMain () {scanf ("%d%d",&n,&s); for(inti=n;i>=0; i--) for(intj=s;j>=0; j--) if(i!=n| | j!=s) f[i][j]= (f[i+1][j+1]* (n-i) * (S-J) +f[i+1][j]* (n-i) *j+f[i][j+1]*i* (S-J) +1.0*s*n)/(1.0*s*n-i*j); printf ("%.4f", f[0][0]); return 0;}
"POJ2096" Collecting Bugs