题意

从$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. UEditor1.2.6.0在.net环境下使用

    UEditor1.2.6.0 1.百度百科词条 2.UEditor官方网站 [CKEditor+CKFinder的配置实用,可查看博主另一篇文章] 第一次接触UEditor还是在2011年的下半年里, ...

  2. 应用wavesurfer.js绘制音频波形图小白极速上手总结

    一.简介 1.1  引   人生中第一份工作公司有语音识别业务,需要做一个web网页来整合语音引擎的标注结果和错误率等参数,并提供人工比对的语音标注功能(功能类似于TranscriberAG等),(博 ...

  3. 小程序--scroll-view的横向滑动无效

  4. poium测试库介绍

    poium测试库前身为selenium-page-objects测试库,我在以前的文章中也有介绍过:这可能是最简单的Page Object库,项目的核心是基于Page Objects实现元素定位的封装 ...

  5. 【刷题】牛客网看到的鹅厂ML面筋-部分问题RecSys相关

    昨天下午六点半的电话面试,其实我已经有了一个不错的实习offer ,不是特别想去腾讯了,没有太怎么准备,接的电话. 整个面试15分钟,开始就是自我介绍,接着问项目,和上一段百度实习经历.问题大致如下: ...

  6. 将root 当成arraylist放入数据sturts2 入门笔记

    刚启动idea 就报出错误 [-- ::,] Artifact -sturts2:war exploded: Error during artifact deployment. See server ...

  7. java循环1

    public class f_w { public static void main(String []args) { int a=0; System.out.print("_info__w ...

  8. Ansible小记

    参考网址: https://www.iyunv.com/thread-385359-1-1.html http://blog.51cto.com/215687833/1886305

  9. bugku crypto 告诉你一个秘密(ISCCCTF)

    emmmm....有点坑 题目: 636A56355279427363446C4A49454A7154534230526D6843 56445A31614342354E326C4B4946467A57 ...

  10. 抽奖大转盘 js代码

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...