hdu-6397-容斥
Character Encoding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1141 Accepted Submission(s): 433
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.
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.
2 3 3
2 3 4
3 3 3
128 3 340
0
7
903
#include<bits/stdc++.h>
using namespace std;
#define LL long long
LL mod=;
LL inv[]={,},jc[]={,},jc_n[]={,};
void init(){
for(int i=;i<=;++i){
jc[i]=jc[i-]*i%mod;
inv[i]=(mod-mod/i)*inv[mod%i]%mod;
jc_n[i]=jc_n[i-]*inv[i]%mod;
}
}
LL C(LL r,LL n){
if(r>n) return ;
return jc[n]*jc_n[r]%mod*jc_n[n-r]%mod;
}
int main()
{
init();
int t;
LL n,m,k;
cin>>t;
while(t--){
scanf("%lld%lld%lld",&n,&m,&k);
LL ans=C(m-,k+m-);
for(LL i=;i<=m;++i){
LL res=C(i,m)*C(m-,m+k--i*n)%mod;
if(i%==) ans=(ans-res+mod)%mod;
else ans=(ans+res)%mod;
}
printf("%lld\n",ans);
}
return ;
}
hdu-6397-容斥的更多相关文章
- HDU 4135 容斥
问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. ...
- HDU 2841 容斥 或 反演
$n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 284 ...
- HDU 1695 容斥
又是求gcd=k的题,稍微有点不同的是,(i,j)有偏序关系,直接分块好像会出现问题,还好数据规模很小,直接暴力求就行了. /** @Date : 2017-09-15 18:21:35 * @Fil ...
- HDU 4059 容斥初步练习
#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...
- hdu 1220 容斥
http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others) Memory ...
- Co-prime HDU - 4135_容斥计数
Code: #include<cstdio> #include<cstring> #include<cmath> #include<iostream> ...
- How many integers can you find HDU - 1796_容斥计数
Code: #include<cstdio> using namespace std; typedef long long ll; const int R=13; ll a[R]; ll ...
- HDU 6397 Character Encoding (组合数学 + 容斥)
题意: 析:首先很容易可以看出来使用FFT是能够做的,但是时间上一定会TLE的,可以使用公式化简,最后能够化简到最简单的模式. 其实考虑使用组合数学,如果这个 xi 没有限制,那么就是求 x1 + x ...
- 多校 HDU 6397 Character Encoding (容斥)
题意:在0~n-1个数里选m个数和为k,数字可以重复选: 如果是在m个xi>0的情况下就相当于是将k个球分割成m块,那么很明显就是隔板法插空,不能为0的条件限制下一共k-1个位置可以选择插入隔板 ...
- HDU 6397(2018多校第8场1001) Character Encoding 容斥
听了杜教的直播后知道了怎么做,有两种方法,一种构造函数(现在太菜了,听不懂,以后再补),一种容斥原理. 知识补充1:若x1,x2,.....xn均大于等于0,则x1+x2+...+xn=k的方案数是C ...
随机推荐
- Bash 和 Zsh 开启 vi-mode
Bash 和 Zsh 开启 vi-mode bash 有两种操作模式,分别是 emacs 和 vi . 在 bash 中 set -o vi # 临时开启 vi 模式 vi ~/.bashrc # 在 ...
- NPOI导入excel文件为DataTable,使用SqlBulkCopy添加到数据库表
public DataTable ExcelToDataTable(Stream stream, string fileName) { DataTable data = new DataTable() ...
- 2017-2018-2 20165306 实验四《Android开发基础》实验报告
实验四<Android开发基础>实验报告 实验报告封面 实验内容 Android程序设计-1 实验要求: 参考<Java和Android开发学习指南(第二版)(EPUBIT,Java ...
- dplyr-高效的数据变换与整理工具--转载
1.背景简介 在数据分析工作中,经常需要对原始的数据集进行清洗.整理以及变换.常用的数据整理与变换工作主要包括:特定分析变量的选取.满足条件的数据记录的筛选.按某一个或几个变量排序.对原始变量进行加工 ...
- CSDN-markdown编辑器语法——字体、字号与颜色
Markdown是一种可以使用普通文本编辑器编写的标记语言,通过类似HTML的标记语法,它可以使普通文本内容具有一定的格式.但是它本身是不支持修改字体.字号与颜色等功能的! CSDN-markd ...
- Scrapy创建爬虫项目
1.打开cmd命令行工具,输入scrapy startproject 项目名称 2.使用pycharm打开项目,查看项目目录 3.创建爬虫,打开CMD,cd命令进入到爬虫项目文件夹,输入scrapy ...
- centos7 Python3终端中敲击方向键显示「^[[C^[[D」
[root@localhost src]# python3 Python ( , ::) [GCC (Red Hat -)] on linux Type "help", " ...
- Oracle简单语句查询
语法3-1:简单查询语句语法 SELECT [DISTINCT] * |列名称[AS][列别名],列名称[AS][列别名],...FROM 表名称[表别名]; 在整个简单查询之中,主要有两个子句完成: ...
- 牛客OI周赛4-提高组 A K小生成树(kmst)
K小生成树(kmst) 思路: 暴力+并查集 枚举边的子集,用并查集判断两个点联不联通 代码: #include<bits/stdc++.h> using namespace std; # ...
- spring cloud: zuul(四): 正则表达式匹配其他微服务(给其他微服务加版本号)
spring cloud: zuul(四): 正则表达式匹配其他微服务(给其他微服务加版本号) 比如我原来有,spring-boot-user微服务,后台进行迭代更新,另外其了一个微服务: sprin ...