题目描述

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 then 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.

输入

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.

输出

For each test case, display the answer modulo 998244353 in a single line.

样例输入

4
2 3 3
2 3 4
3 3 3
128 3 340

样例输出

1
0
7
903
题意是从0-n-1这n个数中选m个,和为k的方案数,可以重复选择
也就是将k分成m份,每份为0-n-
也就是将k+m分成m份,每份为1-n
假设没有上限n,答案就是隔板法 C(k+m-,m-)
这里面肯定计算了有大于n的情况
假设我们从这k+m里面拿出一个n,然后将剩下的分成非空的m份,再把这个n加到其中的一份当中,那么至少有一份是大于n的,同样的道理,如果拿出c个n,那么至少有c份是大于n的,因为这里是至少,而不是一定有c份大于n,这其中有包含关系,所以需要容斥一下
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int p=;
const int N=1e6+;
int T,n,m,k;
ll fac[N],inv[N];
ll poww(ll x,int y)
{
ll ret=;
while(y)
{
if (y&) ret=ret*x%p;
x=x*x%p;
y>>=;
}
return ret;
}
void pre()
{
fac[]=;
for (int i=;i<N;i++) fac[i]=fac[i-]*i%p;
inv[N-]=poww(fac[N-],p-);
for (int i=N-;i>=;i--) inv[i]=inv[i+]*(i+)%p;
}
ll C(int a,int b)
{
return fac[a]*inv[b]%p*inv[a-b]%p;
}
ll solve(int n,int m,int k)
{
if(1ll*(n-)*m<k) return ; ll ans=C(k+m-,m-);
int nn=k/n;
for (int i=;i<=nn;i++)
{
ll tmp=C(k-i*n+m-,m-)*C(m,i)%p; if (i&) ans=(ans-tmp+p)%p;
else ans=(ans+tmp)%p;
}
return ans;
}
int main()
{
pre();
scanf("%d",&T);
while (T--)
{
scanf("%d%d%d",&n,&m,&k);
printf("%lld\n",solve(n,m,k));
}
return ;
}

杭电多校第八场-A-Character Encoding的更多相关文章

  1. Acesrc and Travel(2019年杭电多校第八场06+HDU6662+换根dp)

    题目链接 传送门 题意 两个绝顶聪明的人在树上玩博弈,规则是轮流选择下一个要到达的点,每达到一个点时,先手和后手分别获得\(a_i,b_i\)(到达这个点时两个人都会获得)的权值,已经经过的点无法再次 ...

  2. 2019 杭电多校第八场 HDU - 6665 Calabash and Landlord 两矩形分平面

    题意 给出两个矩形,问这两个矩形把平面分成了几部分. 分析 不需要什么高级技能,只需 “简单” 的分类讨论. (实在太难写了,对拍找出错误都不想改 推荐博客,其中有个很好的思路,即只讨论答案为2,3, ...

  3. [2019杭电多校第八场][hdu6667]Roundgod and Milk Tea

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6667 题目大意是说n个班级,每个班级有ai人和bi杯茶,每个人只能喝其他班的茶并且只能喝一杯.问最多有 ...

  4. 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)

    以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...

  5. HDU 5745 La Vie en rose (DP||模拟) 2016杭电多校联合第二场

    题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> # ...

  6. HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场

    题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...

  7. HDU 5742 It's All In The Mind (贪心) 2016杭电多校联合第二场

    题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> ...

  8. HDU 5734 Acperience (公式推导) 2016杭电多校联合第二场

    题目:传送门. #include <iostream> #include <algorithm> #include <cstdio> #include <cs ...

  9. HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场

    题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...

随机推荐

  1. Pandas dataframe数据写入文件和数据库

    转自:http://www.dcharm.com/?p=584 Pandas是Python下一个开源数据分析的库,它提供的数据结构DataFrame极大的简化了数据分析过程中一些繁琐操作,DataFr ...

  2. oracle数据库分页原理

    Oracle数据库的rownum 在Oracle数据库中,分页方式没有MySql这样简单,它需要依靠rownum来实现.Rownum表示一条记录的行号,值得注意的是它在获取每一行后才赋予.因此,想指定 ...

  3. [ML] the notes

    "Machine Learning is not who has the best algorithm that wins. It is who has the most data.&quo ...

  4. 11.22Daily Scrum(2)

    人员 任务分配完成情况 明天任务分配 王皓南 实现网页上视频浏览的功能.研究相关的代码和功能.984 数据库测试 申开亮 实现网页上视频浏览的功能.研究相关的代码和功能.985 实现视频浏览的功能 王 ...

  5. c# CLR无法从 COM 上下文 0x51cd20 转换为 COM 上下文 0x51ce90

    调试菜单--->异常---->managed debugging assistants栏下ContextSwitchDeadlock 前面的√去掉

  6. Spring学习(二)—— java的动态代理机制

    在学习Spring的时候,我们知道Spring主要有两大思想,一个是IoC,另一个就是AOP,对于IoC,依赖注入就不用多说了,而对于Spring的核心AOP来说,我们不但要知道怎么通过AOP来满足的 ...

  7. JSP在页面加载时调用servlet的方法

    方法:先在JS里面写一个调用servlet的事件(可以利用ajax),然后利用<body>标签的onload调用这个事件. 代码如下: jsp文件代码如下: <%@ page lan ...

  8. 利用JavaScriptSerializer类 进行Json对象的序列化和反序列化和过滤

    项目下载:JavaScriptSerializer_对JSON对象序列化与反序列化及过滤器 利用<JavascriptSerializer类> 进行Json对象的序列化和反序列化 1. 首 ...

  9. SVM之对偶问题

    SVM之问题形式化 >>>SVM之对偶问题 SVM之核函数 SVM之解决线性不可分 写在SVM之前——凸优化与对偶问题 前一篇SVM之问题形式化中将最大间隔分类器形式化为以下优化问题 ...

  10. 【Redis】- 总结精讲

    本文围绕以下几点进行阐述 1.为什么使用redis2.使用redis有什么缺点3.单线程的redis为什么这么快4.redis的数据类型,以及每种数据类型的使用场景5.redis的过期策略以及内存淘汰 ...