hdu6397 Character Encoding(容斥+经典隔板法)

题目链接
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

题意:给定n,m,k
要求x1+x2+x3+.。。。xm=k的方案数。
以下题解摘抄自某位大佬。在这里插入图片描述

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5;
const int mod=998244353;
ll n,m,k,f[maxn],inv[maxn];
ll quick(ll a,ll b){ 
    ll ans=1;  
    a=a%mod;
    while(b!=0){
        if(b&1) ans=(ans*a)%mod;
        b>>=1;
        a=(a*a)%mod;
    }
    return ans;
}
ll C(ll a,ll b)
{
    if(b<a) return 0;
    return f[b]*inv[a]%mod*inv[b-a]%mod;
}
int main() 
{
    int T,flag;
    f[0]=1;inv[0]=quick(f[0],mod-2);
    for(int i=1;i<maxn;++i)
    f[i]=(f[i-1]*i)%mod,inv[i]=quick(f[i],mod-2);
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld %lld %lld",&n,&m,&k);
        ll ans=C(m-1,m+k-1);
        if(k==0)
        {
            printf("1\n");continue;
        }
        if(k<n)
        {
            printf("%lld\n",C(k,m-1+k));continue;
        }
        if(k>m*(n-1))
        {
            printf("0\n");continue;
        }
        for(int i=1;i<=m;++i)
        {
            flag=(i&1)?-1:1;
            ans+=flag*C(i,m)*C(m-1,m-1+k-i*n)%mod;
            ans=(ans%mod+mod)%mod;
        }
        printf("%lld\n",ans);
    }
}
发布了328 篇原创文章 · 获赞 1 · 访问量 9113

猜你喜欢

转载自blog.csdn.net/qq_42479630/article/details/105169212