hdu 6397 Character Encoding (生成函数)

时间:2021-12-29 08:06:54

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
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),对于这样一个式子,我们对前面一部分二项式展开可得

hdu 6397 Character Encoding (生成函数)


 #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 &lpar;组合数学 &plus; 容斥&rpar;

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

  2. 多校 HDU 6397 Character Encoding &lpar;容斥&rpar;

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

  3. HDU - 6397 Character Encoding 2018 Multi-University Training Contest 8 &lpar;容斥原理&rpar;

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

  4. HDU-6397&lpar;2018 Multi-University Training Contest 8&rpar; Character Encoding&lpar;生成函数&plus;组合数学&rpar;

    题意 从$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 &quot&semi;Cp1251&quot&semi; character encoding&period;

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

  7. Character Encoding tomcat&period;

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

  8. Character Encoding in &period;NET

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

  9. java&period;sql&period;SQLException&colon; Unsupported character encoding 'utf8mb4'&period;

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

随机推荐

  1. netaddr 0&period;7&period;12

    Pythonic manipulation of IPv4, IPv6, CIDR, EUI and MAC network addresses https://pypi.python.org/pyp ...

  2. 《Android开发艺术探索》读书笔记 &lpar;4&rpar; 第4章 View的工作原理

    本节和<Android群英传>中的第3章Android控件架构与自定义控件详解有关系,建议先阅读该章的总结 第4章 View的工作原理 4.1 初始ViewRoot和DecorView ( ...

  3. Android客户端通过socket与服务器通信

    android端--Client package com.sec.chatroomandroid; import java.io.BufferedReader; import java.io.Buff ...

  4. JS打开摄像头并截图上传

    直入正题,JS打开摄像头并截图上传至后端的一个完整步骤 1. 打开摄像头主要用到getUserMedia方法,然后将获取到的媒体流置入video标签 2. 截取图片主要用到canvas绘图,使用dra ...

  5. Spring Cloud Alibaba基础教程:Nacos配置的多文件加载与共享配置

    前情回顾: <Spring Cloud Alibaba基础教程:使用Nacos实现服务注册与发现> <Spring Cloud Alibaba基础教程:支持的几种服务消费方式> ...

  6. linux audit &lpar;9&rpar;--生成audit报表

    aureport这个命令可以生成一个总结性的柱状图报表,默认情况下,在/var/log/audit目录下的所有日志文件都会生成一个报表,也可以使用如下命令来指定一个不同的文件,aureport opt ...

  7. Linux常用系统命令

    致歉:各位看到此博客的朋友们 因为命令的数量挺多的很多命令也都很简单  我就总结了一下具体的命令和这个命令是做什么的,主要的使用方法是链接到http://man.linuxde.net/的网站的,请各 ...

  8. 代理(Proxy&rpar;模式简介

    一.代理(Proxy)模式简介 代理模式是结构型模式. 代理模式给某一个对象提供一个代理对象,并由代理对象控制对原对象的引用. 代理对象要继承于抽象主题,并控制原对象的引用 二.简单例子 抽象主题类 ...

  9. PKUWC2019退役记

    PKUWC2019 退役记 \(day1\): 进场看T1,发现是个对于所有边的子集求权值和的计数题,以为是个主旋律那样的神仙容斥,完全不会做(退役flag*1).T2是个和虚树有关的计数题,第一个s ...

  10. centos无法安装vmvare-tools的问题

    不要使用 vmware 自带的 tools, 版本太老了. 从这里下载:https://github.com/rasa/vmware-tools-patches.git 直接下载或者使用下面的命令: ...