杭电多校第八场 Character Encoding(容斥)

Character Encoding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 526    Accepted Submission(s): 200


 

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

 Source

2018 Multi-University Training Contest 8

思路:x1 + x2 + x3 +......+ xm = k当xi>=0时整数解C(m - 1,k + m - 1)(隔板法来求),但要求的xi的范围为0~n-1,容斥的搞一下就行了

#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int MAXN = 200005;
const int MOD = 998244353;
typedef long long LL;
LL fac[MAXN],facinv[MAXN];
LL qpow(LL a, LL b)
{
    LL res = 1;
    while(b) {
        if(b & 1) res = (res * a) % MOD;
        a = (a * a) % MOD;
        b >>= 1;
    }
    return res;
}
void init()
{
    fac[0] = 1;
    for(int i = 1; i < MAXN; i++)
        fac[i] = fac[i - 1] * i % MOD;
    facinv[MAXN - 1] = qpow(fac[MAXN - 1], MOD - 2);
    for(int i = MAXN - 1; i > 0; i--)
        facinv[i - 1] = facinv[i] * i % MOD;
}
LL C(LL n, LL m)
{
    if(n < 0 || m < 0 || m > n)
        return 0;
    return fac[n] * facinv[m] % MOD * facinv[n - m] % MOD;
}
int main(void)
{
    int T,n,m,k;
    init();
    LL ans;
    scanf("%d",&T);
    while(T--) {
         ans = 0;
        scanf("%d %d %d",&n,&m,&k);
        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) % MOD;
        }
        cout << ans << endl;
    }
    return 0;
}
/*
4
2 3 3
2 3 4
3 3 3
128 3 340
*/

猜你喜欢

转载自blog.csdn.net/GYH0730/article/details/81712970