题目链接
1 #include <bits/stdc++.h>
2 using namespace std;
3 typedef long long ll;
4 inline ll read(){
5 int x = 0, f = 1; char ch = getchar();
6 while(ch > '9' || ch < '0'){if (ch == '-') f = -1; ch = getchar();}
7 while(ch >= '0' && ch <= '9'){ x = x*10+ch-'0'; ch = getchar();}
8 return x*f;
9 }
10
11 /************************************************************************/
12
13 const int maxn = 50;
14 int n, m;
15 double dp[maxn*maxn*2][maxn][maxn];
16
17 int main(){
18 int t;
19 t = read();
20 while(t--){
21 n = read(); m = read();
22 memset(dp, 0, sizeof(dp));
23 dp[1][1][1] = 1;
24 for(int i = 1;i <= n*m;i++){
25 for(int j = 1;j <= n;j++){
26 for(int k = 1;k <= m;k++){
27 if(dp[i][j][k]){
28 dp[i+1][j+1][k] += dp[i][j][k] * (n-j)*k/(1.0*(n*m-i));
29 dp[i+1][j][k+1] += dp[i][j][k] * (m-k)*j/(1.0*(n*m-i));
30 dp[i+1][j+1][k+1] += dp[i][j][k] * (n-j)*(m-k)/(1.0*(n*m-i));
31 if(j < n || k < m)
32 dp[i+1][j][k] += dp[i][j][k] * (j*k-i)/(1.0*(n*m-i));
33 }
34 }
35 }
36 }
37 double ans = 0.0;
38 for(int i = 1;i <= n*m;i++){
39 ans += dp[i][n][m]*i;
40 }
41 printf("%.12lf
", ans);
42 }
43 return 0;
44 }