2018 Multi-University Training Contest 8 1001 Character Encoding

本文探讨了计算机科学中字符编码的基本原理,特别是ASCII编码,并通过一个具体的数学问题深入讲解了如何利用组合数学来解决字符编码中涉及的组合计数问题。文章提供了详细的解题思路和代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Character Encoding

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


 

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

 

题解

即求\sum_{i=1}^{m}x_{i}=k(0<=x<n)整数解的个数。

若x无上界限制时,由隔板法很容易得出解的个数为S(m)=\textrm{C}_{m-1}^{k+m-1}

因为有上界限制,因此要减去超过上界的部分

可设有y个值超过了上界,依然利用隔板法可求出解的个数为F(y)=\textrm{C}_{y}^{m}*\textrm{C}_{m-1}^{k-yn+m-1}

设S(y)表示有y个值超过上界时的解

可得S(y)=F(y)-S(y+1)

S(0)即为解

 

代码


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 998244353;
const int mmax = 3e5 + 10;
ll fac[mmax + 5];
ll inv[mmax + 5];
ll qpow(ll a, ll b) 
{ 
	ll r = 1, t = a; 
	while (b) { 
		if (b & 1)r = (r*t) % mod;
		b >>= 1;t = (t*t) % mod;
	}
	return r;
}
void init()
{
	fac[0] = 1;
	for (int i = 1;i <= mmax;i++) fac[i] = fac[i - 1] * 1ll * i%mod;
	inv[mmax] = qpow(fac[mmax], mod - 2);
	for (int i = mmax - 1;~i;i--) inv[i] = inv[i + 1] * 1ll * (i + 1) % mod;
}
ll C(ll n, ll m)
{
	if (m>n) return 0;
	if (m == n || m == 0) return 1;
	return fac[n] * 1ll * inv[n - m] % mod*inv[m] % mod;
}
int main() 
{
	init();
	ll t, n, m, k, ans;
	cin >> t;
	while (t--)
	{
		cin >> n >> m >> k;
		ans = 0;
		for (int i = 0;i <= m;i++)
		{
			if(i%2==0)
				ans += C(m, i)*C(k - i*n + m - 1, m - 1)%mod;
			else
				ans -= C(m, i)*C(k - i*n + m - 1, m - 1)%mod;
			ans = (ans + mod) % mod;
		}
		cout << ans << endl;
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值