hdu Character Encoding 容斥

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个盒子,k个小球,每个盒子最多只能放n-1个小球。

若盒子数量没有限制,则为C(m+k-1,m-1)个。

有了限制条件,如果有i个盒子有大于等于n小球,就把k=k-i*n,可以采用上述公式了。i为奇减偶加。就是

sum( (-1)^i * C(m , i) * C(m-1+k-n*i , m-1) );

#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<deque>
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll M = 2e5 + 100;
const ll mod=998244353;
ll inv[M],f[M],f_n[M];
void init()//线性求逆元
{
    inv[0]=0;f[0]=1;f_n[0]=1;
    inv[1]=1;f[1]=1;f_n[1]=1;
    for(int i=2;i<M;i++){
        f[i]=f[i-1]*i%mod;
        inv[i]=(mod-mod/i)*inv[mod%i]%mod;
        f_n[i]=f_n[i-1]*inv[i]%mod;
    }
}
int t,n,m,k;
ll C(int n,int m)
{
    if(n<m||n<0||m<0)
        return 0;
    ll res=f[n];
    res=res*f_n[m]%mod*f_n[n-m]%mod;
    return res%mod;
}
int main()
{
    init();
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&m,&k);
        ll ans=0,res;
        for(int i=0;i<=k/n;i++)
        {
            res=C(m,i)*C(k+m-1-i*n,m-1)%mod;
            if(i&1)
                ans=(ans-res+mod)%mod;
            else
                ans=(ans+res)%mod;
            //cout<<res<<endl;
        }
        printf("%lld\n",ans);
    }
}

猜你喜欢

转载自blog.csdn.net/liluoyu_1016/article/details/81811067