Hdu5245 --- Joyful (expected), joyful

Source: Internet
Author: User

Hdu5245 --- Joyful (expected), joyful

Problem Description
Sakura has a very magical tool to paint Wils. 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
The precise answer in the first test case is about 3.56790123.

Source
The 2015 ACM-ICPC China Shanghai Metropolitan Programming Contest

Recommend
We have carefully selected several similar problems for you: 5244 5243 5242 5241 5240

Consider the probability of each grid being coated, and add the probability to the end.

/*************************************** * *********************************> File Name: hdu5245.cpp> Author: ALex> Mail: zchao1995@gmail.com> Created Time: thursday, May 28, 2015 ******************************** **************************************** /# include <functional> # include <algorithm> # include <iostream> # include <fstream> # include <cstring> # include <cstdio> # include <cmath> # include <cstdlib> # include <queue> # include <stack> # include <map> # include <bitset> # include <set> # include <vector> using namespace std; const double pi = acos (-1.0); const int inf = 0x3f3f3f3f; const double eps = 1e-15; typedef long LL; typedef pair <int, int> PLL; int main () {int t, icase = 1; scanf ("% d", & t); while (t --) {int n, m, k; scanf ("% d", & n, & m, & k); double ans = 0; for (int I = 1; I <= n; ++ I) {for (int j = 1; j <= m; ++ j) {LL ways = (LL) (I-1) * (I-1) * m; ways + = (LL) (j-1) * (j-1) * n; ways + = (LL) (n-I) * (n-I) * m; ways + = (LL) (m-j) * n; ways-= (LL) (I-1) * (I-1) * (j-1) * (j-1); ways-= (LL) (I-1) * (I-1) * (m-j); ways-= (LL) (j-1) * (j-1) * (n-I); ways-= (LL) (n-I) * (m-j) * (m-j); LL sum = (LL) m * n; double p = ways * 1.0/sum; double tmp = 1; for (int l = 1; l <= k; ++ l) {tmp * = p;} ans + = (1-tmp );}} printf ("Case # % d: %. 0f \ n ", icase ++, ans);} return 0 ;}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.