HDU-6397(2018 Multi-University Training Contest 8) Character Encoding(生成函数+组合数学)
题意
从$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(生成函数+组合数学)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- tmux resurrect 配置
概述 tmux 用了很长时间了, 快捷键定制了不少, 唯一的遗憾是没法保存 session, 每次关机重开之后, 恢复不到之前的 tmux session. 虽然也能忍受, 但是每天都手动打开之前的 ...
- Java基础系列--05_面向对象
1.概述: (1)面向过程:将问题一步一步的解决的过程(详细步骤),在C语言中所有的代码都是基于过程化的代码. (2)面向对象:面向对象是基于面向过程的编程思想,所有的事情都交由创建出来的对象去指挥. ...
- Raneto部署知识库平台&支持中文搜索
目录 环境 更新软件包 部署 Raneto 知识库平台 安装 Node 环境 安装 node 管理工具 查看 node 列表 安装需要的Node版本 使用 淘宝NPM源 git 使用代理设置,大陆地区 ...
- mongo 监听指定语句
class Program { private static string conn = "mongodb://47.104.206.56:27017"; //数据库名称 priv ...
- html简单的知识
分布式版本控制git pwd查询当前目录 ls ls -la git config --global user.name xxx git config --global user. ...
- Fum uc M-R ko P's R
Milr-Rabin Dodod Avlo se \(n-1\) e \(u\cdot 2^t\). hen goch'n Toizz lme \([1,n-1]\) e \(l\). cak fe ...
- RedisCache 缓存
/// <summary> /// 这是包装过公用的,用于本站而已. /// </summary> /// <author>rixiao</author> ...
- vedio-js的视频插件用法
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- Bootstrap 模态框(Modal)插件id冲突
<!DOCTYPE html><html><head> <meta charset="utf-8"> <titl ...
- python format() 函数
转载 https://www.cnblogs.com/wushuaishuai/p/7687728.html 正文 Python2.6 开始,新增了一种格式化字符串的函数 format() ,它增强了 ...