ZOJ 3822 Domination (probability DP)
Domination Time Limit: 8 Seconds Memory Limit: 131072 KB Special Judge
Edward is the headmaster of Marjar University. He is enthusiastic about chess and often plays chess with his friends. What's more, he bought a large decorative chessboardNRows andMColumns.
Every day after work, Edward will place a chess piece on a random empty cell. A few days later, he found the chessboard wasDominatedBy the chess pieces. That means there is at least one chess piece in every row. Also, there is at least one chess piece in every column.
"That's interesting! "Edward said. He wants to know the expectation number of days to make an empty chessboardN×MDominated. Please write a program to help him.
Input
There are multiple test cases. The first line of input contains an integerTIndicating the number of test cases. For each test case:
There are only two integersNAndM(1 <=N,M<= 50 ).
Output
For each test case, output the expectation number of days.
Any solution with a relative or absolute error of at most 10-8 will be accepted.
Sample Input
21 32 2
Sample Output
3.0000000000002.666666666667
Question: Randomly place a piece in a N * M board and place it in a grid every day. Calculate each column in each row
The number of days that are covered by pawns.
Train of Thought: As shown in, dp [I] [j] [k] indicates the probability that the j column of the I row is overwritten by k pawns in the upper left corner (regardless
Where the pawns are placed, you can move them to the corresponding place in the upper left corner. k is the number of forks in area 1 ).
When a pawn is placed in area 1: dp [I] [j] [k] = (r * c-k)/(n * m-k) * dp [I] [j] [k + 1];
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink">
Authorization/authorization + PHA + tbHG5dfTt8W1vcf40/authorization/Ct8W1vcO/uPbH + NPyttTTprXEzPW8/authorization + PHA + authorization = "brush: java;"> # include
# Include
# Include
Using namespace std; const int maxn = 55; double dp [maxn] [maxn] [maxn * maxn]; bool visited [maxn] [maxn] [maxn * maxn]; int n, m; double DP (int r, int c, int num) {if (visited [r] [c] [num]) return dp [r] [c] [num]; if (r = 0 | c = 0) return DP (r + 1, c + 1, num + 1) + 1; if (r> = n & c> = m) return 0; double ans = 0.0, p = n * m-num, q = r * c-num; if (num