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. Web自动化测试 二 ----- HTML

    HTML 一.结构 html> 与 </html> 之间的文本描述网页 <body> 与 </body> 之间的文本是可见的页面内容 <h1> 与 ...

  2. C#学习笔记:ListBox控件的用法

    样式如下: 实现的代码一: using System;using System.Collections.Generic;using System.ComponentModel;using System ...

  3. Python爬虫入门:爬取豆瓣电影TOP250

    一个很简单的爬虫. 从这里学习的,解释的挺好的:https://xlzd.me/2015/12/16/python-crawler-03 分享写这个代码用到了的学习的链接: BeautifulSoup ...

  4. Field部分参数设置含义

    /** * Field.Store.COMPRESS:压缩保存,用于长文本或二进制数据 * Field.Store.YES:保存 * Field.Store.NO:不保存 * * Field.Inde ...

  5. django基础知识之后台管理Admin站点:

    Admin站点 通过使用startproject创建的项目模版中,默认Admin被启用 1.创建管理员的用户名和密码 python manage.py createsuperuser 然后按提示填写用 ...

  6. scrapy实战7爬取搜狗微信:

    爬取微信热门文章标题,内容,内容地址,微信公众号,公众号地址,发布日期等 如图 源码地址:https://github.com/huwei86/sougouweixin

  7. 如何用ModelSim对Xilinx ISE产生的网表进行仿真

    图: 在对设计的芯片进行测试时,经常要用到FPGA,可是里面的仿真工具却不如Modelsim那么好用,且在规模比较大时,ISE在仿真时,软件经常会报告内存限制的问题,此时一般会切换到Modelsim软 ...

  8. SQL Server 根据日期分组、 根据时间段分组(每三个小时一组)

    所用数据表: 一.根据日期分组 1. 使用convert() 函数方式 --根据年月 ),CreatTime,)日期,COUNT(*) 次数,sum(Money)总数 from Orders ),Cr ...

  9. 宏旺半导体深度剖析嵌入式存储芯片eMMC原理 一篇概括大全

    eMMC 一直是嵌入式存储市场最主流的选择,除了读写速度快.性价比高外,在节省空间方面也是相当优秀,今天宏旺半导体就和大家详细聊聊eMMC. eMMC 是 embedded MultiMediaCar ...

  10. you-get视频下载

    项目主页 https://github.com/soimort/you-get 使用you-get库一些简单命令下载视频音乐 you-get是一个基于python3的下载器,没有客户端或者可视化工具, ...