2018hdu杭电多校第八场 hdu6397 Character Encoding(组合数+容斥定理/生成函数(母函数))

Character Encoding

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

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


题意:求m个0...n-1的数组成和为k的种类

题解:这题有两种做法:1)生成函数(母函数)2)容斥定理

推理过程省略。。

最后公式是 \sum_{i=0}^{n/k}(-1)^i\cdot C_{m}^{i}\cdot C_{m+k-n*i-1}^{m-1}

代码:

#include 
using namespace std;
#define rep(i,s,e) for(int i=s; i=s; i--)
typedef long long ll;
const ll mod = 998244353;

ll powmod(ll a,ll b) {
	ll res=1;
	a%=mod;
	assert(b>=0);
	for(; b; b>>=1) {
		if(b&1)res=res*a%mod;
		a=a*a%mod;
	}
	return res;
}

const int N = 2e5+5;

ll fac[N], inv[N];

void init() {
	// 预处理阶乘
	fac[0] = fac[1] = 1;
	rep (i, 2, N) fac[i] = i * fac[i-1] % mod;
	// 求阶乘逆元
	inv[N-1] = powmod(fac[N-1], mod-2);
	per (i, 0, N-1) inv[i] = inv[i+1] * (i+1) % mod;
}

ll comb(ll n, ll m) { // c(n, m) = n!/(m! * (n-m)!)
	if (n<0 || m<0 || n

 

你可能感兴趣的:(2018多校,hdu,题解,2018多校,hdu,题解)