题意

从$0$到$n-1$的数字里可重复的取至多$m$个数的和等于$k$的方案数。

思路

显然的生成函数的思路为构造

$(1+x+x^{2}+...+x^{n-1})^{m}$

那么$x^{k}$的系数即答案。等比数列求和后得到

$ \frac {(1-x^n)^m} {(1-x)^m}$

对分子二项式展开得到

$(1-x^n)^m = \sum_{i=0}^m C_m^{i}(-1)^i * x^{n*i}$

对分母根据泰勒展开得到

$(1-x)^{-m} = \sum_{j = 0}^{\infty }C_{m+j-1}^{j}x^{j}$

代码

#include <bits/stdc++.h>
#define DBG(x) cerr << #x << " = " << x << endl; using namespace std; const int N = 200000 + 5;
const int mod = 998244353;
typedef long long LL; int t, n, m, k;
LL fac[N], invf[N]; LL add(LL a, LL b) {
LL res = a + b;
if(res < 0) res += mod;
return res % mod;
} LL mul(LL a, LL b) {
LL res = a * b;
if(res < 0) res += mod;
return res % mod;
} LL qpow(LL a, LL b) {
LL res = 1;
while(b) {
if(b & 1) res = mul(res, a);
a = mul(a, a);
b /= 2;
}
return res;
} void init() {
fac[0] = fac[1] = 1;
for(int i = 2; i < N; i++) fac[i] = mul(fac[i - 1], 1LL * i);
invf[N - 1] = qpow(fac[N - 1], mod - 2);
for(int i = N - 2; i >= 0; i--) invf[i] = mul(invf[i + 1], 1LL * i + 1);
} LL C(int n, int m) {
if(n < 0 || m < 0 || n < m) return 0;
return mul(fac[n], mul(invf[m], invf[n - m]));
} int main() {
init();
scanf("%d", &t);
while(t--) {
LL ans = 0;
scanf("%d%d%d", &n, &m, &k);
for(LL i = 0; k - n * i >= 0; i++) {
LL j = k - n * i;
LL tmp = (i % 2 == 0 ? 1 : -1);
ans = add(ans, mul(tmp, mul(C(m, i), C(m + j - 1, m - 1))));
}
printf("%lld\n", ans % mod);
}
return 0;
}

  

HDU-6397(2018 Multi-University Training Contest 8) Character Encoding(生成函数+组合数学)的更多相关文章

  1. hdu 4915 Parenthese sequence--2014 Multi-University Training Contest 5

    主题链接:http://acm.hdu.edu.cn/showproblem.php?pid=4915 Parenthese sequence Time Limit: 2000/1000 MS (Ja ...

  2. hdu 4902 Nice boat--2014 Multi-University Training Contest 4

    题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=4902 Nice boat Time Limit: 30000/15000 MS (Java/Othe ...

  3. hdu 4925 Apple Tree--2014 Multi-University Training Contest 6

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4925 Apple Tree Time Limit: 2000/1000 MS (Java/Others ...

  4. HDU校赛 | 2019 Multi-University Training Contest 6

    2019 Multi-University Training Contest 6 http://acm.hdu.edu.cn/contests/contest_show.php?cid=853 100 ...

  5. HDU校赛 | 2019 Multi-University Training Contest 5

    2019 Multi-University Training Contest 5 http://acm.hdu.edu.cn/contests/contest_show.php?cid=852 100 ...

  6. HDU校赛 | 2019 Multi-University Training Contest 4

    2019 Multi-University Training Contest 4 http://acm.hdu.edu.cn/contests/contest_show.php?cid=851 100 ...

  7. HDU校赛 | 2019 Multi-University Training Contest 3

    2019 Multi-University Training Contest 3 http://acm.hdu.edu.cn/contests/contest_show.php?cid=850 100 ...

  8. HDU校赛 | 2019 Multi-University Training Contest 2

    2019 Multi-University Training Contest 2 http://acm.hdu.edu.cn/contests/contest_show.php?cid=849 100 ...

  9. HDU校赛 | 2019 Multi-University Training Contest 1

    2019 Multi-University Training Contest 1 http://acm.hdu.edu.cn/contests/contest_show.php?cid=848 100 ...

随机推荐

  1. c编译器字节对齐指令

    #pragma pack (n)             作用:C编译器将按照n个字节对齐.#pragma pack ()               作用:取消自定义字节对齐方式. #pragma ...

  2. YASnippet - emacs 的代码片段管理工具

    添加 snippet M-x 然后输入 yas-new-snippet 回车 RET,会出现一个新的 buffer # -*- mode: snippet -*- # name: # key: # - ...

  3. Andriod studio 打包aar

    因为项目不同,有些公用库而且还是c++的,还有一些带资源的,简单的复制遇到库升级又是一轮配置,编译成aar则解决这些麻烦. 但是默认andriod studio的make moudle只生成debug ...

  4. linux驱动简单介绍

     linux驱动简单介绍 驱动基本介绍 驱动.顾名思义就是“驱使硬件设备行动”.设备驱动与底层硬件之间打交道,按照硬件设备的具体操作方式来读写设备寄存器,最终完成一系列操作. 设备 驱动充当了应用程序 ...

  5. MYSQL内置MYSQL数据库中你可以得到的信息

    1:help_topic  可以查看函数帮助,例如:SELECT * from help_topic WHERE name='concat' 可以查看concat函数. 2:SLOW_LOG 慢查询日 ...

  6. openwrt 里LUA程序怎么获取POST数据?

    https://www.zhihu.com/question/31579325 作者:齐葛链接:https://www.zhihu.com/question/31579325/answer/28342 ...

  7. .NET开源快速开发框架Colder发布 (NET452+AdminLTE版)

    .NET开源快速开发框架Colder(NET452+AdminLTE版) 引言 半年前将基于Easyui的快速开发框架开源,三个版本(NET4.52,NETCore和NET4.0)总共荣获200+星, ...

  8. 三十六、fetch

    https://developer.mozilla.org/zh-CN/docs/Web/API/Fetch_API

  9. Python类和对象

    目录 类与对象 其他方法 继承 经典类和新式类 派生 组合 接口.归一化设计与抽象类 继承实现的原理 子类中调用父类的方法 指名道姓 super()方法 多态与多态性 封装 单下划线开头 双下划线开头 ...

  10. Python----逻辑回归

    逻辑回归 1.逻辑函数 sigmoid函数就出现了.这个函数的定义如下: sigmoid函数具有我们需要的一切优美特性,其定义域在全体实数,值域在[0, 1]之间,并且在0点值为0.5. 那么,如何将 ...