/* Expectation of DP inverse recursive solution: a software has s sub-systems, which produce n kinds of bugs. Someone finds a bug one day. This bug belongs to a sub-system, the probability that a bug belongs to a subsystem is 1/s. The probability of a bug belongs to a certain 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, DP [0] [0] is the answer to the question DP [I] [J] is converted from four States to 1: DP [I] [J] finds that a state already has I classification, and the probability of J systems p1 = I/N * j/S 2: DP [I + 1] [J] does not belong to this category, but belongs to this system bug probability P2 = (1-I/n) * j/S 3: DP [I] [J + 1] found to belong to this system, but does not belong to this classification of bug probability P3 = I/N * (1-j/s) 4: DP [I + 1] [J + 1] is found to belong to this system and does not belong to this classification of bug probability P4 = (1-I/n) * (1-j/s) So: DP [I] [J] = p1 * DP [I] [J] + p2 * DP [I + 1] [J] + P3 * DP [I] [J + 1] + P4 * DP [I + 1] [J + 1] + 1; simplified: DP [I] [J] = (DP [I + 1] [J] * (N * j-I * j) + dp [I] [J + 1] * (I * s-I * j) + dp [I + 1] [J + 1] * (N * s-J * n-I * s + I * j) + N * s) /(n * s-I * j); */# include <stdio. h> # include <algorithm> # include <string. h ># include <iostream> using namespace STD; double DP [1010] [1010]; int main () {int N, S, I, j; while (~ Scanf ("% d", & N, & S) {// memset (DP, 0, sizeof (DP )); DP [N] [s] = 0; for (I = N; I> = 0; I --) {for (j = s; j> = 0; j --) {if (I = N & J = s) continue; DP [I] [J] = (DP [I + 1] [J] * (N * j-I * j) + dp [I] [J + 1] * (I * s-I * j) + dp [I + 1] [J + 1] * (N * s-J * n-I * s + I * j) + N * s) /(n * s-I * j);} printf ("%. 4lf \ n ", DP [0] [0]);} return 0 ;}
Poj 2096 collecting bugs (probability DP)