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 then 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.

 

输入

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.

 

输出

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

 

样例输入

4
2 3 3
2 3 4
3 3 3
128 3 340

 

样例输出

1
0
7
903

在0到n-1选m个数,使其和为k,隔板法的思想,但是选出的数要不大于n,所以要容斥搞一下

结果就是:

#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=200050;
const ll mod=998244353;
ll pos[maxn],ans[maxn],fac[maxn],inv[maxn];
ll qmod(ll a,ll b)
{
    ll ans=1;
    a%=mod;
    while(b)
    {
        if(b&1)
        {
            ans=(ans*a)%mod;
        }
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}
void pre()
{
    fac[0]=fac[1]=1;
    for(int i=2;i<maxn;i++)
    {
        fac[i]=i*fac[i-1]%mod;
    }
    inv[maxn-1]=qmod(fac[maxn-1],mod-2);
    for(int i=maxn-2;i>=0;i--)
    {
        inv[i]=(i+1)*inv[i+1]%mod;
    }
}
ll C(int n,int k)
{
    if(k<0||k>n)
    {
        return 0;
    }
    return fac[n]*inv[k]%mod*inv[n-k]%mod;
}
int main()
{
    ll n,m,k,ans;
    int t;
    scanf("%d",&t);
    pre();
    while(t--)
    {
        scanf("%lld %lld %lld",&n,&m,&k);
        ans=0;
        for(int i=0;i*n<=k;i++)
        {
            if(i&1)
            {
                ans=(ans-C(m,i)*C(k-i*n-1+m,m-1)%mod+mod)%mod;
            }
            else
            {
                ans=(ans+C(m,i)*C(k-i*n-1+m,m-1)%mod)%mod;
            }
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值