杭电多校第八场-A-Character Encoding
题目描述
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.
输出
样例输入
4
2 3 3
2 3 4
3 3 3
128 3 340
样例输出
1
0
7
903
题意是从0-n-1这n个数中选m个,和为k的方案数,可以重复选择
也就是将k分成m份,每份为0-n-
也就是将k+m分成m份,每份为1-n
假设没有上限n,答案就是隔板法 C(k+m-,m-)
这里面肯定计算了有大于n的情况
假设我们从这k+m里面拿出一个n,然后将剩下的分成非空的m份,再把这个n加到其中的一份当中,那么至少有一份是大于n的,同样的道理,如果拿出c个n,那么至少有c份是大于n的,因为这里是至少,而不是一定有c份大于n,这其中有包含关系,所以需要容斥一下
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int p=;
const int N=1e6+;
int T,n,m,k;
ll fac[N],inv[N];
ll poww(ll x,int y)
{
ll ret=;
while(y)
{
if (y&) ret=ret*x%p;
x=x*x%p;
y>>=;
}
return ret;
}
void pre()
{
fac[]=;
for (int i=;i<N;i++) fac[i]=fac[i-]*i%p;
inv[N-]=poww(fac[N-],p-);
for (int i=N-;i>=;i--) inv[i]=inv[i+]*(i+)%p;
}
ll C(int a,int b)
{
return fac[a]*inv[b]%p*inv[a-b]%p;
}
ll solve(int n,int m,int k)
{
if(1ll*(n-)*m<k) return ; ll ans=C(k+m-,m-);
int nn=k/n;
for (int i=;i<=nn;i++)
{
ll tmp=C(k-i*n+m-,m-)*C(m,i)%p; if (i&) ans=(ans-tmp+p)%p;
else ans=(ans+tmp)%p;
}
return ans;
}
int main()
{
pre();
scanf("%d",&T);
while (T--)
{
scanf("%d%d%d",&n,&m,&k);
printf("%lld\n",solve(n,m,k));
}
return ;
}
杭电多校第八场-A-Character Encoding的更多相关文章
- Acesrc and Travel(2019年杭电多校第八场06+HDU6662+换根dp)
题目链接 传送门 题意 两个绝顶聪明的人在树上玩博弈,规则是轮流选择下一个要到达的点,每达到一个点时,先手和后手分别获得\(a_i,b_i\)(到达这个点时两个人都会获得)的权值,已经经过的点无法再次 ...
- 2019 杭电多校第八场 HDU - 6665 Calabash and Landlord 两矩形分平面
题意 给出两个矩形,问这两个矩形把平面分成了几部分. 分析 不需要什么高级技能,只需 “简单” 的分类讨论. (实在太难写了,对拍找出错误都不想改 推荐博客,其中有个很好的思路,即只讨论答案为2,3, ...
- [2019杭电多校第八场][hdu6667]Roundgod and Milk Tea
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6667 题目大意是说n个班级,每个班级有ai人和bi杯茶,每个人只能喝其他班的茶并且只能喝一杯.问最多有 ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
- HDU 5745 La Vie en rose (DP||模拟) 2016杭电多校联合第二场
题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> # ...
- HDU 5744 Keep On Movin (贪心) 2016杭电多校联合第二场
题目:传送门. 如果每个字符出现次数都是偶数, 那么答案显然就是所有数的和. 对于奇数部分, 显然需要把其他字符均匀分配给这写奇数字符. 随便计算下就好了. #include <iostream ...
- HDU 5742 It's All In The Mind (贪心) 2016杭电多校联合第二场
题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> ...
- HDU 5734 Acperience (公式推导) 2016杭电多校联合第二场
题目:传送门. #include <iostream> #include <algorithm> #include <cstdio> #include <cs ...
- HDU 5724 Chess (状态压缩sg函数博弈) 2016杭电多校联合第一场
题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^ ...
随机推荐
- [leetcode-693-Binary Number with Alternating Bits]
Given a positive integer, check whether it has alternating bits: namely, if two adjacent bits will a ...
- gcc与g++区别以及相关参数详解
---恢复内容开始--- 原文链接:g++和gcc的区别 一 .二者区别 gcc和g++都是GNU(一个组织)的编译器. 1.对于.c后缀的文件,gcc把它当做是C程序:g++当做是C++程序: 2. ...
- JS设置cookie,删除cookie(引)
JS设置cookie,删除cookie(引) js设置cookie有很多种方法. 第一种:(这个是w3c官网的代码) <script> //设置cookie function setCoo ...
- lintcode-142-O(1)时间检测2的幂次
142-O(1)时间检测2的幂次 用 O(1) 时间检测整数 n 是否是 2 的幂次. 样例 n=4,返回 true; n=5,返回 false. 挑战 O(1) time 标签 比特位操作 思路 使 ...
- TCP系列31—窗口管理&流控—5、TCP流控与滑窗
一.TCP流控 之前我们介绍过TCP是基于窗口的流量控制,在TCP的发送端会维持一个发送窗口,我们假设发送窗口的大小为N比特,网络环回时延为RTT,那么在网络状况良好没有发生拥塞的情况下,发送端每个R ...
- winform Form窗体和UserControl用户空间嵌入Panel容器并填充
private void sbtbflList_Click(object sender, EventArgs e) { ucxmflList ucfl = new ucxmflList();//用户控 ...
- 【week4】技术随笔psp
本周psp
- 浅述Try {} Catch{} 作用
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Test ...
- winform中文本框添加拖拽功能
对一个文本框添加拖拽功能: private void txtFolder_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataP ...
- 【bzoj1231】[Usaco2008 Nov]mixup2 混乱的奶牛 状态压缩dp
题目描述 混乱的奶牛[Don Piele, 2007]Farmer John的N(4 <= N <= 16)头奶牛中的每一头都有一个唯一的编号S_i (1 <= S_i <= ...