航电多校第八场-A-Character Encoding

题目描述

In computer science, a character is a letter, a digit, a punctuation mark or some other similar symbol. Since computers can only process numbers, number codes are used to represent characters, which is known as character encoding. A character encoding system establishes a bijection between the elements of an alphabet of a certain size n and integers from 0 to n?1. Some well known character encoding systems include American Standard Code for Information Interchange (ASCII), which has an alphabet size 128, and the extended ASCII, which has an alphabet size 256.

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 then 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.

输入

The first line of input is a single integer T (1≤T≤400), the number of test cases.
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.

输出

For each test case, display the answer modulo 998244353 in a single line.

样例输入

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-1
也就是将k+m分成m份,每份为1-n
假设没有上限n,答案就是隔板法 C(k+m-1,m-1)
这里面肯定计算了有大于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=998244353;
const int N=1e6+10;
int T,n,m,k;
ll fac[N],inv[N];
ll poww(ll x,int y)
{
    ll ret=1;
    while(y)
    {
        if (y&1) ret=ret*x%p;
        x=x*x%p;
        y>>=1;
    }
    return ret;
}
void pre()
{
    fac[0]=1;
    for (int i=1;i<N;i++) fac[i]=fac[i-1]*i%p;
    inv[N-1]=poww(fac[N-1],p-2);
    for (int i=N-2;i>=0;i--) inv[i]=inv[i+1]*(i+1)%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-1)*m<k)  return 0;

    ll ans=C(k+m-1,m-1);
    int nn=k/n;
    for (int i=1;i<=nn;i++)
    {
        ll tmp=C(k-i*n+m-1,m-1)*C(m,i)%p;

        if (i&1) 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 0;
}

原文地址:https://www.cnblogs.com/tetew/p/9502518.html

时间: 2024-10-22 05:29:33

航电多校第八场-A-Character Encoding的相关文章

2019 杭电多校 第八场

2019 Multi-University Training Contest 8 补题链接:2019 Multi-University Training Contest 8 1003 Acesrc and Good Numbers HDU 6659 题意 定义 \(f(d, n)\) 为十进制下 \(1\) 到 \(n\) 所有数的数位中数字 \(d\) 出现的次数.给定 \(x\),找出最大的 \(n(n \le x)\) 满足 \(f(d, n) = n\). 题解 看到了一个神仙做法. 显

HDU 6397(2018多校第8场1001) Character Encoding 容斥

听了杜教的直播后知道了怎么做,有两种方法,一种构造函数(现在太菜了,听不懂,以后再补),一种容斥原理. 知识补充1:若x1,x2,.....xn均大于等于0,则x1+x2+...+xn=k的方案数是C(k+m-1,m-1)种(貌似紫书上有,记不太清了). 知识补充2:若限制条件为n(即x1,x2....xn均小于n,假设有c个违反,则把k减掉c个n(相当于把c个超过n的数也变成大于等于0的),就可以套用知识1的公式了. 则最后的答案为sum( (-1)^c * C(m , c) * C(m-1+

多校第八场:图论出度

HDU 4948 这题比赛的时候遗憾了,我看了这道题,然后觉得挺简单的. 刚开始一看题上,想到的就是拓扑排序,然后脑子想啊想--感觉就是拓扑排序的逆序,然后发现挺水的-- 因为说了要想发展某个城市的话,就必须有另一个城市作为它发展的前提,即城市u->w这样连边,表示要想发展城市w,前提是u已经是发展过的城市了.那这样的话不是很简单嘛. 即统计出出度最多的就是第一个要发展的城市了,因为u->w这样连边可以看出算出出度最多的依次从大到小排序就行了. 哎呀,不过可惜了,因为看见没人交这题,然后也不敢

2014 HDU多校弟八场H题 【找规律把】

看了解题报告,发现看不懂 QAQ 比较简单的解释是这样的: 可以先暴力下达标,然后会发现当前数 和 上一个数 的差值是一个 固定值, 而且等于当前数与i(第i个数)的商, 于是没有规律的部分暴力解决,有规律的套公式 //#pragma comment(linker, "/STACK:16777216") //for c++ Compiler #include <stdio.h> #include <iostream> #include <cstring&g

HDU 5742 It&#39;s All In The Mind (贪心) 2016杭电多校联合第二场

题目:传送门. 题意:求题目中的公式的最大值,且满足题目中的三个条件. 题解:前两个数越大越好. #include <iostream> #include <algorithm> #include <cstdio> #include <cstring> using namespace std; int gcd(int a,int b) { if(!b) return a; return gcd(b,a%b); } int main() { int t; ci

2018航电多校练习第9场-快速幂

Rikka with Badminton Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 53    Accepted Submission(s): 44 Problem Description In the last semester, Rikka joined the badminton club. There are n st

2019 杭电多校 第五场

2019 Multi-University Training Contest 5 补题链接:2019 Multi-University Training Contest 5 罚时爆炸 自闭场 1004 equation (HDU 6627) 题意: 给定一个整数 \(C\) 和 \(N\) 组 \(a_i,b_i\),求 \(∑_{i=1}^N|a_i\cdot x + b_i| = C\) 的所有解,如果有无穷多个解就输出 -1. 思路 分类讨论 分类讨论去绝对值.根据 \(b_i / a_i

[补]2019HDU杭电多校第五场H

红小豆又被奇怪的东西卡住了 参考于:思路https://www.cnblogs.com/st1vdy/p/11309280.html 样例https://www.cnblogs.com/dd-bond/p/11308155.html HDU-6631 line symmetric 多边形轴对称类问题.关于多边形轴对称目前可以公开的情报可见第一篇blog的大佬画的图,主要就是奇偶问题.本题主要思路是枚举实现找轴和验证对称,注意判自交的方式. 初步认识可以做一下hdu3902. 在下还是专注于讲心路

HDU 5745 La Vie en rose (DP||模拟) 2016杭电多校联合第二场

题目:传送门. 这是一道阅读理解题,正解是DP,实际上模拟就能做.pij+1 指的是 (pij)+1不是 pi(j+1),判断能否交换输出即可. #include <iostream> #include <algorithm> #include <cstdio> #include<cstring> using namespace std; int t,n; char str1[100009],str2[5009]; char tmp[5009]; int m