HDU 6397 Character Encoding(容斥定理)

Character Encoding

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


 

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

 

 

Recommend

chendu   |   We have carefully selected several similar problems for you:  6408 6407 6406 6405 6404 

#include<bits/stdc++.h>
using namespace std;

#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define read(x,y) scanf("%d%d",&x,&y)

#define root l,r,rt
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define ll long long
const int  maxn =2e5+5;
const int mod=998244353;
/*
题目大意:题目意思很经典,
有m个数相加和为k,每个数范围不超过n,
问方案数有多少。

经典问题,我是按容斥定理理解写的,
如果没有限制,题目很简单,就是(m+k-1,m-1)这样的组合方案,
可以考虑把m-1个隔板插到k个数中,这样就好理解多了。
如果有超出n限制的数呢?容斥定理容斥下,
枚举如果有一个,两个,。。直到k-i*n小于0为止。

对每个枚举出的容斥项,计算方法还是类同于隔板法,
但要乘上其系数的影响C(m,i)。这样容斥下去。。

然后就是组合数的基本功了,求组合数的带模形式,
就用阶乘逆元搞一下就行了。
*/

int n,m,k;///需要阶乘及其阶乘的逆元

///阶乘逆元+组合数取余
 ll fac[maxn],inv[maxn];///阶乘取余
 ll powmod(ll x,ll y){ll t;for(t=1;y;x=x*x%mod,y>>=1) if(y&1) t=t*x%mod;return t;}
 void init(ll ub)
 {
     fac[0]=1;for(ll i=1;i<=ub;i++) fac[i]=fac[i-1]*i%mod;
     inv[ub]=powmod(fac[ub],mod-2);
     for(ll i=ub-1;i>=0;i--) inv[i]=inv[i+1]*(i+1)%mod;
}
ll C(ll n,ll m)
{
    return ((fac[n]*inv[m]%mod)*inv[n-m]%mod);
}
///扩展欧几里得+求逆元
ll exgcd(ll a,ll b,ll &x,ll &y){
    if(!b) { x=1;y=0;return a; }
    ll d=exgcd(b,a%b,y,x);
    y -= a/b*x;
    return d;
}
ll get_inv(ll a,ll n){ll x,y;exgcd(a,n,x,y);return (x+n)%n;}///可能是负数}

int main()
{
    init(maxn-3);
    int t;scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d%d",&n,&m,&k);
        ll ans=C(m+k-1,m-1),c=1;
        for(ll i=1;i<=m;i++)
        {
            c=C(m,i);
            if(k-i*n<0) break;
            ll tp=c*C(m+k-i*n-1,m-1)%mod;
            ///cout<<c<<" "<<C(m+k-i*n-1,m-1)<<endl;
            if(i&1) ans=(ans-tp+mod)%mod;
            else ans=(ans+tp)%mod;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值