2018 Multi-University Training Contest 8 (hdu6397 Character Encoding)

Problem Description

In computer science, a character is a letter, a digit, a punctuation mark or some other similar symbol. Since computers can only process numbers, number codes are used to represent characters, which is known as character encoding. A character encoding system establishes a bijection between the elements of an alphabet of a certain size n and integers from 0 to n−1. Some well known character encoding systems include American Standard Code for Information Interchange (ASCII), which has an alphabet size 128, and the extended ASCII, which has an alphabet size 256.

For example, in ASCII encoding system, the word wdy is encoded as [119, 100, 121], while jsw is encoded as [106, 115, 119]. It can be noticed that both 119+100+121=340 and 106+115+119=340, thus the sum of the encoded numbers of the two words are equal. In fact, there are in all 903 such words of length 3 in an encoding system of alphabet size 128 (in this example, ASCII). The problem is as follows: given an encoding system of alphabet size n where each character is encoded as a number between 0 and n−1 inclusive, how many different words of length m are there, such that the sum of the encoded numbers of all characters is equal to k?

Since the answer may be large, you only need to output it modulo 998244353.

 

Input

The first line of input is a single integer T (1≤T≤400), the number of test cases.

Each test case includes a line of three integers n,m,k (1≤n,m≤105,0≤k≤105), denoting the size of the alphabet of the encoding system, the length of the word, and the required sum of the encoded numbers of all characters, respectively.

It is guaranteed that the sum of n, the sum of m and the sum of k don't exceed 5×106, respectively.

 

Output

For each test case, display the answer modulo 998244353 in a single line.

 

Sample Input

4

2 3 3

2 3 4

3 3 3

128 3 340

Sample Output

1

0

7

903

题意:给出n种数0,1,2,3...n-1,可以重复的任选m个数,问选出的m个数和为k的方案数。

思路:这里给出题解为官方题解的做法,赛后直播杜教的方法我还得继续学习。

先粘一下官方题解

2018 Multi-University Training Contest 8 (hdu6397 Character Encoding)_第1张图片

图中说的容斥原理相当于

ans=C(m,0)C(k-0*n+m-1,m-1)-C(m,1)C(k-1*n+m-1,m-1)+C(m,2)C(k-2*n+m-1,m-1)-C(m,3)C(k-3*n+m-1,m-1)...

就是常规的容斥,至于为什么图中说C(m,p)C(k-np+m-1,m-1),从m个地方选出p个违反,然后只要将这p个么个减n就能全部合法了所以是C(k-np+m-1,m-1)。至于C(k+m-1,m-1)这个公式,查书吧。。。

代码:

const int MAXN = 202020;
const int mod = 998244353;
int fac[MAXN], inv[MAXN];
int n, m, k;
long long pow_mod(int a, int b)
{
    long long ret = 1;
    for(; b; b >>= 1, a = (long long)a * a % mod)
        if(b & 1)
            ret = ret * a % mod;
    return ret;
}
void init()
{
    fac[0] = 1;
    for(int i = 1; i < MAXN; i++)
        fac[i] = (long long)fac[i - 1] * i % mod;
    inv[MAXN - 1] = pow_mod(fac[MAXN - 1], mod - 2);
    for(int i = MAXN - 1; i > 0; i--)
        inv[i - 1] = (long long) inv[i] * i % mod;
}
long long C(int n, int m)
{
    if(n < 0 || m < 0 || m > n)
        return 0;
    return (long long)fac[n] * inv[m] % mod * inv[n - m] % mod;
}
int main()
{
    init();
    int T_T;
    scanf("%d",&T_T);
    while(T_T--)
    {
        scanf("%d%d%d", &n, &m, &k);
        int ans = 0;
        for(int c = 0; c * n <= k; c++)
        {
            if(c & 1) ans = (ans - C(m, c) * C(k - c * n + m - 1, m - 1) % mod + mod) % mod;
            else ans = (ans + C(m, c) * C(k - c * n + m - 1, m - 1)) % mod;
        }
        printf("%d\n", ans);
    }
    return 0;
}
 

你可能感兴趣的:(2018 Multi-University Training Contest 8 (hdu6397 Character Encoding))