Boring game

Boring game

\(Description\)

The athletic meet began, fitness dish small cocoa did not report any events, and then the students play a very boring game.
A game board on a square of n * n squares composition is firstly uniformly randomly filled positive integer between 1 and m in each box (filled squares per average number of different), and cocoa small uniform randomly selected number of k from 1 to m (the number may be selected not on the board), they appear black squares on the board, black lines are provided with a whole row R, column C has been black entire column, you can obtain small cocoa 2 ^ (R + C) fraction.
Now small cocoa want to know is how much his expectations score, can you help him?

\(Input\)

The first line contains three positive integers n, m, k.

\(Output\)

Line contains only a real number, the score is desired, if the answer to> 10 ^ 99 to 10 ^ 99 output, the output is considered correct if and only if you output standard output relative error does not exceed 10-6.

\(Sample Input\)

1 2 1

\(Sample Output\)

2.5
[explain] Sample
1 fill 1, selected from 1 or 2, a score of 2 ^ 2 ^ 2 = 4 and 1 = 0 1 square respectively; 1 in the filled squares 1, 2, 1 is selected from or 2, scores were 0 = 2 ^ 2 ^ 2 = 1 and 4, it is desirable score of (4 + 4 + 1 + 1) 4 = 2.5.

\(Data Constraint\)

For 30% of the data, 2≤n≤5, m≤10;
for 60% of the data, 2≤n≤10, m≤200;
to 100% of the data, 2≤n≤300, n * n≤m≤ 100000, n≤k≤m.

Code

#include<cstdio>
using namespace std;

const int N = 300;
double c[N + 5] , cc[100005] , ans;
int n , m , k , p;

int main()
{
    scanf("%d%d%d", &n , &m , &k);
    c[0] = cc[0] = 1;
    for(register int i = 1; i <= n; i++) c[i] = c[i - 1] / i * (n - i + 1);
    for(register int i = 1; i <= m; i++) cc[i] = cc[i - 1] / (m - i + 1) * (k - i + 1);
    for(register int i = 0; i <= n; i++)
        for(register int j = 0; j <= n; j++)
        {
            int p = (i + j) * n - i * j;
            if (p > k) continue;
            ans += c[i] * c[j] * cc[p];
        }
    if (ans > 1e99) ans = 1e99;
    printf("%lf" , ans);
}

Guess you like

Origin www.cnblogs.com/leiyuanze/p/12368642.html