HDU 6397 组合数学+容斥 母函数
Character Encoding
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1473 Accepted Submission(s): 546
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.
容斥写法
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 组合数学+容斥 母函数的更多相关文章
- hdu 5514 Frogs(容斥)
Frogs Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU 5213 分块 容斥
给出n个数,给出m个询问,询问 区间[l,r] [u,v],在两个区间内分别取一个数,两个的和为k的对数数量. $k<=2*N$,$n <= 30000$ 发现可以容斥简化一个询问.一个询 ...
- HDU 2588 思维 容斥
求满足$1<=X<=N ,(X,N)>=M$的个数,其中$N, M (2<=N<=1000000000, 1<=M<=N)$. 首先,假定$(x, n)=m$ ...
- HDU 6397 Character Encoding (组合数学 + 容斥)
题意: 析:首先很容易可以看出来使用FFT是能够做的,但是时间上一定会TLE的,可以使用公式化简,最后能够化简到最简单的模式. 其实考虑使用组合数学,如果这个 xi 没有限制,那么就是求 x1 + x ...
- HDU 1695 GCD 容斥
GCD 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1695 Description Given 5 integers: a, b, c, d, k ...
- HDU 5514 Frogs 容斥定理
Frogs Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5514 De ...
- hdu 5768 Lucky7 容斥
Lucky7 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5768 Description When ?? was born, seven crow ...
- hdu 5212 反向容斥或者莫比
http://acm.hdu.edu.cn/showproblem.php?pid=5212 题意:忽略.. 题解:把题目转化为求每个gcd的贡献.(http://www.cnblogs.com/z1 ...
- ACM-ICPC 2015 沈阳赛区现场赛 F. Frogs && HDU 5514(容斥)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5514 题意:有m个石子围成一圈, 有n只青蛙从跳石子, 都从0号石子开始, 每只能越过xi个石子.问所 ...
随机推荐
- 【java基础】Java锁机制
在读很多并发文章中,会提及各种各样锁如公平锁,乐观锁等等,这篇文章介绍各种锁的分类.介绍的内容如下: 公平锁/非公平锁 可重入锁 独享锁/共享锁(广义) 互斥锁/读写锁(独享锁/共享锁的实现) 乐观锁 ...
- spark性能优化-JVM虚拟机垃圾回收调优
1 2 3 4
- Get value from agent failed: cannot connect to [[ip]:10050]: no rout host
被监控机添加之后,可用性显示红色,鼠标放上去之后显示如标题问题,关闭被监控机器的防火墙,设置setenforce 0,可用性变可用.
- js里面Object的一些方法
1.Object.freeze() 阻止修改现有属性的特性和值,并阻止添加新属性两种用法:Object.freeze( { } ) 和 Object.freeze( object ) <scri ...
- COGS 827. [Tyvj Feb11] 网站计划
输入文件:web.in 输出文件:web.out 简单对比时间限制:1 s 内存限制:128 MB 描述 Description Tyvj的Admin--zhq同学将在寒假开始实行 ...
- 洛谷 P1910 L国的战斗之间谍(水题日常)
题目背景 L国即将与I国发动战争!! 题目描述 俗话说的好:“知己知彼,百战不殆”.L国的指挥官想派出间谍前往I国,于是,选人工作就落到了你身上. 你现在有N个人选,每个人都有这样一些数据:A(能得到 ...
- ldap_modify: No such object (32) matched DN: cn=config
centos 6.9 部署 kerbors ldap 报错 [root@hadoop data]# ldapmodify -Y EXTERNAL -H ldapi:/// -f chdomain.ld ...
- SQLite – GROUP BY
SQLite - GROUP BY SQLite GROUP BY子句中使用与SELECT语句的合作安排相同的数据组. 在GROUP BY子句之前一个SELECT语句的WHERE子句,先于ORDER ...
- liunx 中安装mysql 图形界面 phpmyadmin
是浏览器图形界面 1. 安装mysql 图形管理工具. 2. 使用phpmyadmin 图像化工具. 3.下载地址 http://www.phpmyadmin.net/ 4. 查看是否安装这两个包 ...
- 利用CWinThread实现跨线程父子MFC窗口
利用CWinThread实现跨线程父子MFC窗口 MFC对象只能由创建该对象的线程访问,而不能由其他线程访问. 不遵守该准则将导致断言(assertion)或者无法预知的程序行为等运行期错误. 在多线 ...