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
 

Solution

这题有两种解法,一是std给的容斥,二是生成函数。

在0..n-1中选择m个数(可重复)使之和为k,这是一类整数拆分数问题,当n没有限制时,由隔板法可以得到ans=C(k+m-1,m-1)。好了容斥解法我还没看明白,容斥先鸽一割

进入正题谈谈生成函数,此题中,对于0..n-1这样一个序列每次它可以是选择其中一个数,其用生成函数表现为(1+x+x^2...+x^(n-1)),幂次即代表选择的是哪个数

那么对于m次选择,其随机可重复组合的生成函数g(x)=(1+x+x^2+...+x^(n-1))^m,生成函数中的幂级数是以形式幂级数理论为基础的,也就是说默认级数收敛。

f(x)=1+x+x^2+...+x^(n-1) => f(x)=(1-x^n)/(1-x), g(x)=(1-x^n)^m*(1-x)^(-m),对于这样一个式子,我们对前面一部分二项式展开可得


 #include <bits/stdc++.h>
#define lson rt << 1, l, mid
#define rson rt << 1 | 1, mid + 1, r
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pa = pair<int, int>;
using ld = long double;
ll n, m, k;
const int maxn = 3e5 + ;
const int mod = ;
template <class T>
inline T read(T &ret)
{
int f = ;
ret = ;
char ch = getchar();
while (!isdigit(ch))
{
if (ch == '-')
f = -;
ch = getchar();
}
while (isdigit(ch))
{
ret = (ret << ) + (ret << ) + ch - '';
ch = getchar();
}
ret *= f;
return ret;
}
template <class T>
inline void write(T n)
{
if (n < )
{
putchar('-');
n = -n;
}
if (n >= )
{
write(n / );
}
putchar(n % + '');
}
ll fac[maxn], inv[maxn];
void init()
{
fac[] = fac[] = ;
inv[] = inv[] = ;
for (ll i = ; i < maxn; i++)
{
fac[i] = fac[i - ] * i % mod;
inv[i] = 1ll * (mod - mod / i) * inv[mod % i] % mod;
}
for (ll i = ; i < maxn; i++)
inv[i] = inv[i - ] * inv[i] % mod;
}
ll C(ll x, ll y)
{
if (y > x)
return ;
if (y == || x == )
return ;
return fac[x] * inv[y] % mod * inv[x - y] % mod;
}
int main(int argc, char const *argv[])
{
ios::sync_with_stdio(false);
cin.tie();
cout.tie();
int t;
init();
cin >> t;
while (t--)
{
cin >> n >> m >> k;
ll ans = ;
if (k == )
ans = ;
else if ((n - ) * m < k)
ans = ;
else
{
int c = min(k / n, m);
for (int i = ; i <= c; i++)
{
if (i % == )
ans = (ans + C(m, i) * C(k - i * n + m - , m - ) % mod) % mod;
else
ans = (ans - C(m, i) * C(k - i * n + m - , m - ) % mod + mod) % mod;
}
}
cout << ans << '\n';
}
return ;
}

hdu 6397 Character Encoding (生成函数)的更多相关文章

  1. HDU 6397 Character Encoding (组合数学 + 容斥)

    题意: 析:首先很容易可以看出来使用FFT是能够做的,但是时间上一定会TLE的,可以使用公式化简,最后能够化简到最简单的模式. 其实考虑使用组合数学,如果这个 xi 没有限制,那么就是求 x1 + x ...

  2. 多校 HDU 6397 Character Encoding (容斥)

    题意:在0~n-1个数里选m个数和为k,数字可以重复选: 如果是在m个xi>0的情况下就相当于是将k个球分割成m块,那么很明显就是隔板法插空,不能为0的条件限制下一共k-1个位置可以选择插入隔板 ...

  3. HDU - 6397 Character Encoding 2018 Multi-University Training Contest 8 (容斥原理)

    题意:问有多少种不重复的m个数,值在[0,n-1]范围内且和为k. 分析:当k<=n-1时,肯定不会有盒子超过n,结果是C(m+k-1,k):当k>m*(n-1)时,结果是0. 剩下的情况 ...

  4. HDU-6397(2018 Multi-University Training Contest 8) Character Encoding(生成函数+组合数学)

    题意 从$0$到$n-1$的数字里可重复的取至多$m$个数的和等于$k$的方案数. 思路 显然的生成函数的思路为构造 $(1+x+x^{2}+...+x^{n-1})^{m}$ 那么$x^{k}$的系 ...

  5. A - Character Encoding HDU - 6397 - 方程整数解-容斥原理

    A - Character Encoding HDU - 6397 思路 : 隔板法就是在n个元素间的(n-1)个空中插入k-1个板,可以把n个元素分成k组的方法 普通隔板法 求方程 x+y+z=10 ...

  6. 使用英文版eclipse保存代码,出现some characters cannot be mapped using "Cp1251" character encoding.

    some characters cannot be mapped using "Cp1251" character encoding. 解决办法:方案一: eclipse-> ...

  7. Character Encoding tomcat.

    default character encoding of the request or response body: If a character encoding is not specified ...

  8. Character Encoding in .NET

    https://docs.microsoft.com/en-us/dotnet/standard/base-types/character-encoding#Encodings Characters ...

  9. java.sql.SQLException: Unsupported character encoding 'utf8mb4'.

    四月 12, 2017 3:47:52 下午 org.apache.catalina.core.StandardWrapperValve invoke 严重: Servlet.service() fo ...

随机推荐

  1. jQuery入门——选择器

    jQuery选择器可以分为四类:基础选择器,层级选择器,属性选择器,过滤选择器 基础选择器: <!DOCTYPE html> <html> <head> <m ...

  2. python 基本数据类型之列表

    #列表是可变类型,可以增删改查#字符串不可变类型,不能修改,只能生成新的值. #1.追加 # user_list = ['李泉','刘一','刘康','豆豆','小龙'] # user_list.ap ...

  3. [apue] 使用 poll 检测管道断开

    一般使用 poll 检测 socket 或标准输入时,只要指定 POLLIN 标志位,就可以检测是否有数据到达,或者连接断开: ]; fds[].fd = STDIN_FILENO; fds[].ev ...

  4. JavaScript 基础知识 变量与数据类型

    一.区分大小写 JS中一切(变量/函数名/操作符)都是严格区分大小写的 二.标识符 变量.函数.属性的名字以及函数的参数 命名规则:1.第一个字符可以是字母.下划线.美元符号$ 2.其他的字符可以是字 ...

  5. 浅说——数位DP

    老子听懂了!!!!! 好感动!!! 不说多了:Keywords: 数位DP,二进制,异或. “在信息学竞赛中,有一类与数位有关的区间统计问题.这类问题往往具有比较浓厚的数学味道,无法暴力求解,需要在数 ...

  6. 5分钟快速部署DataDraw数字绘

    经常有小伙伴问,有没有一款好用又免费的画图软件,画画流程图.UML.思维导图?今天就介绍一款开源的在线画图软件,满足各方面人的需求. DataDraw数字绘是一个在线线框图.流程图.网络图.组织结构图 ...

  7. 并发编程-concurrent指南-原子操作类-AtomicLong

    可以用原子方式更新的 long 值.有关原子变量属性的描述,请参阅 java.util.concurrent.atomic 包规范.AtomicLong 可用在应用程序中(如以原子方式增加的序列号), ...

  8. pod update更新error: RPC failed; curl 18 transfer closed with outstanding read data remaining

    1. pod update 的时候出现下边的错误 error: RPC failed; curl 18 transfer closed with outstanding read data remai ...

  9. 2017《java技术预备作业》

    2017<java技术预备作业> 1.阅读邹欣老师的博客,谈谈你期望的师生关系是什么样的? 亦师亦友,很多人这样说,确实,倘若师生之间如果中间有些隔阂最终吃亏的始终是学生.我认为师生之间应 ...

  10. EF 使用遇到过的错误记录备忘

    1. is only supported for sorted input in LINQ to Entities  The method :只支持排序输入实体LINQ 的方法 是使用skip()时没 ...