Joyful
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 515 Accepted Submission(s): 224
However, Sakura is a very naughty girl, so she just randomly uses the tool for K times. More specifically, each time for Sakura to use that tool, she just randomly picks two squares from all the M×N squares, with equal probability. Now, kAc wants to know the expected number of squares that will be painted eventually.
For each test case, there is only one line, with three integers M,N and K.
It is guaranteed that 1≤M,N≤500, 1≤K≤20.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
int T,n,m,k,cas=1;
scanf("%d",&T);
while(T--) {
scanf("%d%d%d",&n,&m,&k);
double ans=0;
for(double i=1;i<=n;i++) {
for(double j=1;j<=m;j++) {
double p=0;
p+=(i-1)*(j-1)*(m-j+1)*(n-i+1);//1
p+=(i-1)*(n-i+1)*m;//2
p+=(i-1)*(m-j)*(n-i+1)*j;//3
p+=(j-1)*(m-j+1)*n;//4
p+=n*m;//5
p+=(m-j)*n*j;//6
p+=(n-i)*(j-1)*i*(m-j+1);//7
p+=(n-i)*i*m;//8
p+=(n-i)*(m-j)*i*j;//9
p=p/n/m/n/m;
ans+=1-pow(1-p,k);//k次染色操作被染色的概率
}
}
printf("Case #%d: %d\n",cas++,int(ans+0.5));
}
return 0;
}