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: RT
Idea: DP [k] [I] [J] indicates the probability that K pieces are removed, and the J column in the I row does not have a piece.
Transfer can be completed in four cases
For example, you can select a grid in (I + 1) * (m-j, total number of available grids (N * m-k + 1)
So DP [k] [I] [J] + = DP [k-1] [I + 1] [J] * (I + 1) * (m-j) /(n * m-k + 1)
2014 Mudanjiang semi-finals D (probability DP) zoj3822