###### HDU 5245 Joyful

Joyful

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 781 Accepted Submission(s): 339

Problem Description
Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks like an M×N matrix. The wall has M×N squares in all. In the whole problem we denotes (x,y) to be the square at the x-th row, y-th column. Once Sakura has determined two squares (x1,y1) and (x2,y2), she can use the magical tool to paint all the squares in the sub-matrix which has the given two squares as corners.

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.

Input
The first line contains an integer T(T≤100), denoting the number of test cases.

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.

Output
For each test case, output ”Case #t:” to represent the t-th case, and then output the expected number of squares that will be painted. Round to integers.

Sample Input
2
3 3 1
4 4 2

Sample Output
Case #1: 4
Case #2: 8

Hint

Source
The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest

My Code：

#include <iostream>
#include <cstdio>
using namespace std;
typedef long long LL;
int main()
{
int T;
cin>>T;
for(int cas=1; cas<=T; cas++)
{
LL m, n, k;
cin>>m>>n>>k;
LL tot = (m*n) * (m*n);
double ret = 0;
for(LL i=1; i<=m; i++)
{
for(LL j=1; j<=n; j++)
{
LL up = ((i-1)*n) * ((i-1)*n);
LL down = ((m-i)*n) * ((m-i)*n);
LL left = ((j-1)*m) * ((j-1)*m);
LL right = ((n-j)*m) * ((n-j)*m);
LL leftup = ((i-1)*(j-1)) * ((i-1)*(j-1));
LL rightup = ((n-j)*(i-1)) * ((n-j)*(i-1));
LL leftdown = ((j-1)*(m-i)) * ((j-1)*(m-i));
LL rightdown = ((m-i)*(n-j)) * ((m-i)*(n-j));
LL ans = up + down + left + right- leftup - rightup - leftdown - rightdown;
///cout<<ans<<endl;
double tp = 1.0;
double p = 1.0*ans/tot;
for(int ii=0; ii<k; ii++)
tp *= p;
ret += 1.0-tp;
}
}
printf("Case #%d: %lld\n",cas,(LL)(ret+0.5));
}
return 0;
}

#### CSA课程：A段架构师的职责

2015年09月22日 14:37

#### HDU 5245 Joyful (概率题 求期望)

2015-08-15 14:33:06

#### acm杭电HDU5245 Joyful 概率问题 期望值（2015上海邀请赛）

2017-05-02 17:03:31

#### hdu5245---Joyful(期望)

2015-05-28 13:45:03

#### hdu 5245 2015 上海邀请赛(期望值 数学概率)

2017-04-29 23:27:44

#### HDU - 5245 Joyful (数学期望+求概率)

2017-04-29 20:26:50

#### 【HDU】5304 Eastest Magical Day Seep Group's Summer【环dp+生成树计数】

2015-07-27 15:58:56

#### hdu5245 Joyful

2016-04-25 22:26:59

#### Java注释规范整理（转）

2011-08-19 10:03:49

HDU 5245 Joyful