Sakura has a very magical tool to paint walls. One day, kAc asked Sakura to paint a wall that looks like an M×NM×N matrix. The wall has M×NM×N squares in all. In the whole problem we denotes (x,y)(x,y) to be the square at the xx-th row, yy-th column. Once Sakura has determined two squares (x1,y1)(x1,y1) and (x2,y2)(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 KKtimes. More specifically, each time for Sakura to use that tool, she just randomly picks two squares from all the M×NM×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 TT(T≤100T≤100), denoting the number of test cases.
For each test case, there is only one line, with three integers M,NM,N and KK.
It is guaranteed that 1≤M,N≤500, 1≤K≤20.
Output
For each test case, output ''Case #t:'' to represent the tt-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.
思路:(参考博客)
求每一个点的贡献,最后累加,一个取两个对角线端点,这个矩形内部的点都会被涂色,也就是贡献要加,算不被染色的贡献会比较好算,就是枚举每个点,以这个点分割大矩形然后求出四个矩形的中所有可能的次数加和减去重复算的,就是这个点不被染色的次数,然后除总次数,就是不被染色的概率,然后求k次的,每个小矩形面积为1,所以贡献度为1。
ac代码:
#include
#include
#include
#include
#include
#include
#include
#include