Character Encoding

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

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
 

容斥写法

x1+x2+...+xm = k (xi>=0) 共有C(k+m-1,m-1) 种 插板法

如果有c个违反条件 把每一个违反条件的x减去n

x1'+x2'+x3'+x4'+x5'+...+xn'= k-c*n xi>=0 共有 C(k-c*n+m-1,m-1)种
    容斥系数    变量选法
ans  = (-1)^c   *   C(m,c)       *     C(k-cn+m-1,m-1)

母函数写法

1+x+x^2+...+x^(n-1)=(1-x^n)/(1-x)

(1+x+x^2+...+x^(n-1))^m

=(1-x^n)^m/(1-x)^m
=(1-x^n)^m*(1-x)^(-m)
=(1-x^n)^m*(sum_ (x^i)*C(m+i-1,m-1)) //上篇博客说的核武器。。。。

ans=x^k 的系数
左边二项式展开 按照每个i 右边应该有k-ni
ans= sum (-1)^i*C(m,i)*C(m+k-n*I-1,m-1)

左边 x^n*i      右边x^(k-n*i)
系数(-1)^i*C(m,i)   系数C(m+k-n*I-1,m-1)

AC代码

#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n");
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl;
using namespace std;
const int maxn= 3e5+;
const int inf = 0x3f3f3f3f,mod=;
typedef long long ll;
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()
{
ll n,m,k,t;
init();
cin>>t;
while(t--)
{
cin>>n>>m>>k;
if(k==)
{
cout<<<<endl;
continue;
}
else if((n-)*m<k)
{
cout<<<<endl;
continue;
}
int c=min(k/n,m);
ll ans=;
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<<endl;
}
}

HDU 6397 组合数学+容斥 母函数的更多相关文章

  1. hdu 5514 Frogs(容斥)

    Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  2. HDU 5213 分块 容斥

    给出n个数,给出m个询问,询问 区间[l,r] [u,v],在两个区间内分别取一个数,两个的和为k的对数数量. $k<=2*N$,$n <= 30000$ 发现可以容斥简化一个询问.一个询 ...

  3. HDU 2588 思维 容斥

    求满足$1<=X<=N ,(X,N)>=M$的个数,其中$N, M (2<=N<=1000000000, 1<=M<=N)$. 首先,假定$(x, n)=m$ ...

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

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

  5. HDU 1695 GCD 容斥

    GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...

  6. HDU 5514 Frogs 容斥定理

    Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...

  7. hdu 5768 Lucky7 容斥

    Lucky7 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 Description When ?? was born, seven crow ...

  8. hdu 5212 反向容斥或者莫比

    http://acm.hdu.edu.cn/showproblem.php?pid=5212 题意:忽略.. 题解:把题目转化为求每个gcd的贡献.(http://www.cnblogs.com/z1 ...

  9. ACM-ICPC 2015 沈阳赛区现场赛 F. Frogs && HDU 5514(容斥)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5514 题意:有m个石子围成一圈, 有n只青蛙从跳石子, 都从0号石子开始, 每只能越过xi个石子.问所 ...

随机推荐

  1. 洛谷 P2680 运输计划

    题目背景 公元 2044 年,人类进入了宇宙纪元. 题目描述 L 国有 n 个星球,还有 n-1 条双向航道,每条航道建立在两个星球之间,这 n-1 条航道连通了 L 国的所有星球. 小 P 掌管一家 ...

  2. 原创:mysql下载 实战 最强最全的无脑白痴版 给小白的爱

  3. java-基于泛型和反射机制的通用比较器实现

    一.前言 Java的比较器是用来对List集合进行排序用的,分为内部比较器和外部比较器两类 内部比较器:被排序的类要 implements Comparable 类,并实现compareTo方法. 外 ...

  4. END - 提交当前的事务

    SYNOPSIS END [ WORK | TRANSACTION ] DESCRIPTION 描述 END END 提交当前事务. 所有当前事务做的修改都可被其它事务看到并且保证在发生崩溃的情况下的 ...

  5. 【转】密码学 :CSP的概念

    转:[密码学]CSP的概念 CSP加密服务提供者(Cryptographic Service Provider)具有一下几个特点: CSP是真正执行密码运算的独立模块 物理上一个CSP由两部分组成:一 ...

  6. Java练习demo 20190402 优惠券扣减

    实体类: package org.jimmy.autosearch2019.pojo; import java.math.BigDecimal; public class TestEntity2019 ...

  7. JavaEE-06 Servlet基础

    学习要点 Servlet生命周期 Servlet API的常用接口和类 Servlet的部署和配置 Servlet处理用户请求 Servlet JSP回顾 JSP技术开发web应用在服务器端生成网页的 ...

  8. postman使用--接口的关联

    前戏 在实际接口测试过程中,接口经常会有关联,比如需要取上一个接口的返回值,然后作为参数传递给下一个接口作为参数,假设我们要获取A接口返回的userid值作为B接口的请求参数 先设置环境,所有接口在一 ...

  9. 暴力破解UltraEdit

    使用x32dbg(x64dbg)做为破解工具: 使用x64dbg 打开 udeit64.exe 点击运行,直到UltraEdit启动,转到符号页: 找到: CheckForUpdatesNoPromp ...

  10. 【洛谷日报#75】浅谈C++指针

    放入我的博客食用效果更佳(有很多oi学习资料) 1.指针基础 1.引用 C++有一个东西叫引用,引用相当于给对象(如:变量)起了另一个名字,引用必须用对象初始化,一旦初始化,引用就会和初始化其的对象绑 ...