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
题意 : 求m 个范围为 0 ~ n - 1的数之和恰好为 K 的种类数。
设这 m 个数 为x1 ,x2......xm
则 有 x1 + x2 + .... + xm = k;
0 <= xi <= n - 1;
求这个方程的整数解有多少组。
我们先不去理会 xi<= n - 1的条件,来考虑所有正整数解的情况。这个很容易用组合数来求解,我们要把 k 个元素分成 m 组,也就是添加 m - 1 块“夹板”,然后在n + m - 1 个位置中找 m - 1 块“夹板”的位置。
然后通过容斥原理来讨论它的逆问题,也就是 x>=n 时的解。我们定义Ak为 xk>=n 并且其他xi>=0时的集合,同样我们用上面的添加“夹板”法来计算Ak的大小,因为有 n 个位置已经被xk所利用了,所以:
由于总共有 m 个元素 所以
由容斥定理可得答案为
(k + m - 1 - x * n > 0 && m>x) ....
要先阶乘和阶乘的逆元预处理下。要不然会 tle 。取模的时候要 + mod 再mod 总共两次 。
不说了,贴代码。。。。。
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <list>
#define INF 0x3f3f3f3f
#define maxn 105000
#define maxnn 6000
#define juzheng 300
#define line cout << "-------------------------" << endl;
#define PI acos(-1.0)
#define mem(a,b) memset(a,b,sizeof(a))
#define fill_(a,b,n) fill(a,a + n,b)
#define esp 1e-9
#define ri(n) scanf("%d",&n)
#define ri2(a,b) scanf("%d %d",&a,&b)
#define ri3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define rd(n) scanf("%lf",&n)
#define rd2(a,b) scanf("%lf %lf",&a,&b)
#define rd3(a,b,c) scanf("%lf %lf %lf",&a,&b,&c)
#define rl(n) scanf("%lld",&n)
#define rl2(a,b) scanf("%lld %lld",&a,&b)
#define rl3(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
#define rui(n) scanf("%u",&n)
#define rui2(a,b) scanf("%u %u",&a,&b)
#define rui3(a,b,c) scanf("%u %u %u",&a,&b,&c)
#define rs(str) scanf("%s",str)
#define pr(n) cout << n << endl
#define debug(str,x) cout << str << ":" << x << endl
#define ll long long
#define int64 __int64
#define ui unsigned int
using namespace std;
const ll mod = 998244353;
const ll p = 998244353;
const ll N = maxn * 2;
//Date:2018-8-15
//Author:HarryBlackCat
ll fac[N],inv[N];
ll quickpow(ll a,ll b){
ll ans=1;
while(b){
if(b&1){
ans=(ans*a)%mod;
}
a=(a*a)%mod;
b>>=1;
}
return ans;
}
ll get_inv(ll x,ll MOD){
return quickpow(x,MOD - 2);
}
void init() {
fac[0]=1;
for (ll i = 1; i < N; i++)
fac[i] = fac[i - 1] * i % mod;
inv[N - 1]=get_inv(fac[N - 1],mod);
for(ll i=N-2; i>=1; i--){
inv[i]=(1LL*inv[i+1]*(i+1))%mod;
}
}
ll C(ll n, ll m) {//pr("fsdfsdsdf");
//return fac[n] * inv(fac[m] * fac[n - m] % mod, mod) % mod;
if(m == 0 || n == m)
return 1;
return (fac[n] * (inv[m] % mod) % mod * (inv[n - m] % mod)) % mod;
}
ll add(ll a) {
while (a < 0) {
a += mod;
}
return a % mod;
}
ll n,m,k;
int main() {
//cin.sync_with_stdio(false);//降低cin,cout时间
int t;
init();
while(~ri(t)) {
while(t--) {
rl3(n,m,k);
if((n - 1) * m < k){
puts("0");
continue;
}
ll ans = 0;
ll sum = k + m - 1;
ll i = 1;
ll j = 0;
while(sum > 0) {
if(sum < m - 1)
break;
//pr(C(m,j));
//pr(C(sum,m - 1));
//printf("sum:%lld m - 1:%lld\n",sum,m - 1);
ans = (ans + add(i * C(m,j)) * C(sum,m - 1));
//printf("m:%lld j:%lld sum:%lld m-1:%lld\n",m,j,sum,m - 1);
//printf("C(%lld,%lld):%lld C(%lld,%lld):%lld\n",m,j,C(m,j),sum,m - 1,C(sum,m - 1));
//printf("add:%lld\n",i * Lucas(m,j) * Lucas(sum,m - 1));
ans %= mod;
sum -= n;
j++;
i *= -1;
}
printf("%lld\n",ans);
}
}
return 0;
}
//100
//100000 100000 100000
//996837032