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. c# 自己实现可迭代的容器

    在c#中我们经常使用到foreach语句来遍历容器,如数组,List,为什么使用foreach语句能够遍历一个这些容器呢,首先的一个前提是这些容器都实现了IEnumerable接口,通过IEnumer ...

  2. 新补充 JSSSS

    条件语句 补充: var a=“hello world” a这个变量是字符串了 对于里面每一个字母来说 他是字节 里面有11个字节 字节总数用length表示 如下: 根据上面的内容咱们又发现了一个运 ...

  3. app兼容测试选择哪些机型才够全面呢?

  4. 渗透测试工具SQLmap

    一.简介 SQLmap 是一款用 Python 编写的开源渗透测试工具,用来自动检测和利用 SQL 注入漏洞. 二.Windows 下安装 2.1 安装 Python 环境 注:Python 3.0会 ...

  5. 关于在使用scrapy-redis分布式踩过的那些坑:

    自己的案列:win7上安装ubuntu (win7作为slaver,ubuntu作为master ) 修改配置文件redis.conf 1)打开配置文件把下面对应的注释掉 # bind 127.0.0 ...

  6. Nginx正向代理和反向代理

    关于代理 说到代理,首先我们要明确一个概念,所谓代理就是一个代表.一个渠道: 此时就设计到两个角色,一个是被代理角色,一个是目标角色,被代理角色通过这个代理访问目标角色完成一些任务的过程称为代理操作过 ...

  7. JAVA接口的继承与集合

    复习 20190701 接口补充 一. java是单继承多实现 单继承: 一个类只能有一个父类 public class D extends D1 { } 2. 多实现 一个类可以同时实现多个接口 当 ...

  8. java将复数字符串虚部实部分离,并实现加减运算

    java字符串构造复数 将字符串分解为复数的实部和虚部 定义一个复数类,数据成员有实部和虚部,根据传参不同构造方法重载,并定义复数的加减方法,以及toString方法.有难度的便是用字符串构造复数了, ...

  9. ServiceFabric极简文档-5.0 Service Fabric有状态与无状态

    Service Fabric 应用程序方案 2017/08/14 作者 Edward Chen Jack Zeng Azure Service Fabric提供了一个可靠而灵活的平台,可用于编写和运行 ...

  10. 1.svn 彻底clear时,注意代码备份 2.借助vc助手加头文件

    1.svn 彻底clear时,注意代码备份 2.不小心彻底clear可以在回收站找到 3.借助vc助手加头文件