Test instructions: There is a n*n wall, now Xiao Ming to brush the wall, if each row of each column has at least one check brush over the stop work, otherwise, each time a random selection of a lattice, if the brush is not brush if not brush, and then rest a minute, to stop working time of the mathematical expectations (before the start has been the M-lattice brush)
Analysis: Probability DP
Status: Dp[i][j] Indicates that there is an I row J column without brush, then it can be transferred to the state of dp[i][j],dp[i-1][j-1],dp[i][j-1],dp[i-1][j-1]
Transfer: dp[i][j]=dp[i][j]* (n-i) (n-j)/n^2+dp[i-1][j]* (i* (n-j))/n^2+dp[i][j-1]* ((n-i) *j)/n^2+dp[i-1][j-1]* (i*j)/n^2
Initialization's not quite understood.
Code:
#include <iostream> #include <cstdio>using namespace std;double dp[2010][2010];int n,m,a[2010],b[2010]; int main () {cin>>n>>m;int x,y;int l=n,r=n;for (int i=0;i<m;i++) {cin>>x>>y;if (!a[x]) l--;if (!b[y]) r--;a[x]=1,b[y]=1;} for (int i=1;i<=l;i++) dp[i][0]=dp[i-1][0]+ (double) n/i;for (int j=1;j<=r;j++) dp[0][j]=dp[0][j-1]+ (double) n/j; for (int i=1;i<=l;i++) {for (int j=1;j<=r;j++) {dp[i][j]= (dp[i-1][j]*i* (n-j) +n*n+dp[i][j-1]*j* (n-i) +dp[i-1][ J-1]*I*J)/(n*n-(n-i) * (N-J));}} printf ("%0.8lf\n", Dp[l][r]);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
! Codeforces 399D Painting the wall-probability DP