1 / * * 2 dp find the desired title. 3 meaning of the questions: s a software sub-systems, will generate n kinds of bug. 4 someone one day find a bug, the bug belongs to some kind of bug, occurs in a subsystem. 5 seek n find all kinds of bug, and each subsystem find bug, so expect to be a number of days. 6 Note that: the number of bug is infinite, so find a bug, appeared in the probability of a subsystem is 1 / S, 7 probability of belonging to a certain type is 1 / n. 8 Solution: . 9 DP [i] [j] denotes the i have found bug, and is present in the j-th system, to achieve the desired target state of the number of days. 10 Obviously, dp [n] [s] = 0, because the target has been reached. The dp [0] [0] is the answer to our requirements. . 11 DP [i] [j] can be converted into the following four state: 12 is DP [i] [j] belongs to a bug found that the i and j th bug system has been found in 13 is DP [i +. 1] [j] found a bug belongs to a new kind of bug, but belong to the j seed systems have found 14 dp [i] [j + 1 ] found that a bug has been found belonging to the i-bug, but belongs to a new subsystem 15 DP [i +. 1] [+ J. 1] found a new bug belongs to a new bug and a subsystem 16 probability of these four were: . 17 P1 * I = J / (S * n-) 18 is P2 = (Ni) * J / (S * n-) . 19 P3 = I * (SJ) / (n-* S) 20 is P4 = (Ni) * (SJ) / (n-* S) 21 is another: desired may be decomposed into a plurality of sub desired weighted sum of weights of sub desired probability of occurrence, i.e., E (aA + bB + ... ) = aE (A) -bE + (B) + ... 22 is therefore: 23 is DP [I, J] * DP = P1 [I, J] + P2 * DP [I +. 1, J] + P3 * DP [ I, J +. 1] + P4 * DP [I +. 1, J +. 1] +. 1; 24 order was: 25 DP [I, J] = (. 1 + P2 * DP [I +. 1, J] + P3 * DP [I, J +. 1] + P4 * DP [I +. 1, J +. 1]) / (. 1-P1) 26 is = ( n*s + (n-i)*j*dp[i+1,j] + i*(s-j)*dp[i,j+1] + (n-i)*(s-j)*dp[i+1,j+1] )/( n*s - i*j ) 27 **/ 28 #include <cstdio> 29 #include <iostream> 30 31 using namespace std; 32 33 double dp[1005][1005]; 34 35 int main() 36 { 37 int n, s, ns; 38 39 cin >> n >> s; 40 ns = n*s; 41 dp[n][s] = 0.0; 42 for (int i = n; i >= 0; i--) 43 for (int j = s; j >= 0; j--) 44 { 45 if ( i == n && j == s ) continue; 46 dp[i][j] = ( ns + (n-i)*j*dp[i+1][j] + i*(s-j)*dp[i][j+1] + (n-i)*(s-j)*dp[i+1][j+1] )/( ns - i*j ); 47 } 48 printf("%.4lf\n", dp[0][0]); 49 50 return 0; 51 }