Character Encoding

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1141    Accepted Submission(s): 433

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
 
Source
   用[0,n)之间的数,填充m个有序位置使得m个位置的数的和是k的不同的方案个数。
  比赛时想到了是放球问题,但是容斥真的不会写,,dp也没调好,自闭了。
  这个问题等价于将k个小球(无差别)放入m个桶中,桶不能为空的方案个数,利用挡板法就是 :k+m个小球有k+m-1个间隙,挑出m-1个间隙插入隔板分成m块对应m个桶,再让每一块的个数减一就是实际放入的个数,这显然是等价的,方案个数就是  C(m-1,k+m-1)。
  但是有个问题是每个桶中的小球不可以大于等于n,因为[0,n)的限制,所以这个方案个数中有一部分是不合法的状态。利用容斥定理减去这些状态 f(i,j)表示包含j号桶在内至少有i个桶中的球数大于等于n的方案个数,不难得出 g(i)=SUM{ f(i,j) }=C(i,m)*C(m-1,k+m-1-i*n) , 然后对g(i)奇加偶减容斥一波。。。
  

 #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-容斥的更多相关文章

  1. HDU 4135 容斥

    问a,b区间内与n互质个数,a,b<=1e15,n<=1e9 n才1e9考虑分解对因子的组合进行容斥,因为19个最小的不同素数乘积即已大于LL了,枚举状态复杂度不会很高.然后差分就好了. ...

  2. HDU 2841 容斥 或 反演

    $n,m <= 1e5$ ,$i<=n$,$j<=m$,求$(i⊥j)$对数 /** @Date : 2017-09-26 23:01:05 * @FileName: HDU 284 ...

  3. HDU 1695 容斥

    又是求gcd=k的题,稍微有点不同的是,(i,j)有偏序关系,直接分块好像会出现问题,还好数据规模很小,直接暴力求就行了. /** @Date : 2017-09-15 18:21:35 * @Fil ...

  4. HDU 4059 容斥初步练习

    #include <iostream> #include <cstring> #include <cstdio> #include <algorithm> ...

  5. hdu 1220 容斥

    http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others)    Memory ...

  6. Co-prime HDU - 4135_容斥计数

    Code: #include<cstdio> #include<cstring> #include<cmath> #include<iostream> ...

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

  8. HDU 6397 Character Encoding (组合数学 + 容斥)

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

  9. 多校 HDU 6397 Character Encoding (容斥)

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

  10. HDU 6397(2018多校第8场1001) Character Encoding 容斥

    听了杜教的直播后知道了怎么做,有两种方法,一种构造函数(现在太菜了,听不懂,以后再补),一种容斥原理. 知识补充1:若x1,x2,.....xn均大于等于0,则x1+x2+...+xn=k的方案数是C ...

随机推荐

  1. C++笔记(2017/2/9)

    this指针 this指针作用就是指向成员函数所作用的对象. 非静态成员函数中可以直接使用this来代表指向该函数作用的对象的指针. 静态成员函数中不能使用this指针. 静态成员 static 定义 ...

  2. Java基础 【类之间的关系】

    在Java与其他面向对象设计语言中,类之间常见的关系有6种 分别是:  依赖.关联.聚合.组合.继承.实现,他们的耦合度依次增强. 其中,关联.聚合.组合关系仅仅是在语义上有所区别,所谓语义就是指上下 ...

  3. 订单BOM、销售BOM、标准BOM

    订单BOM.销售BOM.标准BOM   訂單BOM: 是實際生產時用的BOM, 在標準BOM和銷售BOM基礎上增減物料的BOM銷售BOM: 是為特定客戶設定的BOM, 在主檔數據層次上的BOM, 在生 ...

  4. Codeforces Round #367 (Div. 2) D. Vasiliy's Multiset(01字典树求最大异或值)

    http://codeforces.com/contest/706/problem/D 题意:有多种操作,操作1为在字典中加入x这个数,操作2为从字典中删除x这个数,操作3为从字典中找出一个数使得与给 ...

  5. gulp的使用介绍及技巧

    gulp的使用介绍及技巧 转载: https://www.cnblogs.com/2050/p/4198792.html 1.gulp的安装 首先确保你已经正确安装了nodejs环境.然后以全局方式安 ...

  6. 手把手教你学习R语言

    本文为带大家了解R语言以及分段式的步骤教程! 人们学习R语言时普遍存在缺乏系统学习方法的问题.学习者不知道从哪开始,如何进行,选择什么学习资源.虽然网络上有许多不错的免费学习资源,然而它们多过了头,反 ...

  7. BZOJ 4826 【HNOI2017】 影魔

    题目链接:影魔 这道题就是去年序列的弱化版啊…… 我们枚举最大值的位置\(i\),找出左边第一个比\(a_i\)大的位置\(l\),右边第一个比\(a_i\)大的位置\(r\),然后我们分开考虑一下\ ...

  8. ASP.NET中Page_Load()与Page_Init()的区别

    Page_Init()事件:aspx初始化时触发,只执行一次,常用于页面初始化,并且执行在page_load之前,如果在aspx的程序中需要使用该方法,那么该方法的类需要继承 System.Web.U ...

  9. Ajax_请求get,post案例

    1. 最原始的ajax请求方式 (1). get请求 <%@ Page Language="C#" AutoEventWireup="true" Code ...

  10. 力扣(LeetCode)67. 二进制求和

    给定两个二进制字符串,返回他们的和(用二进制表示). 输入为非空字符串且只包含数字 1 和 0. 示例 1: 输入: a = "11", b = "1" 输出: ...