23333,还是不会。。%%%http://hzwer.com/6276.html
1 #include <bits/stdc++.h> 2 #define LL long long 3 #define lowbit(x) x&(-x) 4 #define inf 0x3f3f3f3f 5 using namespace std; 6 inline int ra() 7 { 8 int x=0,f=1; char ch=getchar(); 9 while (ch<'0' || ch>'9') {if (ch=='-') f=-1; ch=getchar();} 10 while (ch>='0' && ch<='9') {x=x*10+ch-'0'; ch=getchar();} 11 return x*f; 12 } 13 double dp[2005][2005]; 14 int n,m,t1,t2; 15 bool r[2005],c[2005]; 16 int main(int argc, char const *argv[]) 17 { 18 n=ra(); m=ra(); 19 t1=t2=n; 20 for (int i=1; i<=m; i++) 21 { 22 int x=ra(),y=ra(); 23 if (!r[x]) r[x]=1,t1--; 24 if (!c[y]) c[y]=1,t2--; 25 } 26 for (int i=1; i<=n; i++) 27 { 28 dp[i][0]=dp[i-1][0]+(double)n/i; 29 dp[0][i]=dp[0][i-1]+(double)n/i; 30 } 31 for (int i=1; i<=t1; i++) 32 for (int j=1; j<=t2; j++) 33 { 34 dp[i][j]=n*n; 35 dp[i][j]+=i*j*dp[i-1][j-1]; 36 dp[i][j]+=i*(n-j)*dp[i-1][j]; 37 dp[i][j]+=j*(n-i)*dp[i][j-1]; 38 dp[i][j]/=(n*n-(n-i)*(n-j)); 39 } 40 printf("%.10lf ",dp[t1][t2]); 41 return 0; 42 }