abc295e
abc295e
这题主要是一个小trick
那么后面这个就很好算了
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#define fo(i,a,b) for (int (i)=(a);(i)<=(b);(i)++)
#define fd(i,b,a) for (int (i)=(b);(i)>=(a);(i)--)
#define mk(x,y) make_pair((x),(y))
#define A puts("YES")
#define B puts("NO")
using namespace std;
typedef double db;
typedef long long ll;
const ll mo=998244353;
const int N = 2005;
ll d[N], n, m, tot, x, c[N][N], k, ans, a[N][N];
ll power(ll a, ll b) {
ll t = 1, y = a % mo;
while (b) {
if (b & 1) t = t * y % mo;
y = y * y % mo;
b /= 2;
}
return t;
}
void solve(int x) {
ll sum = 0;
fo(i, 0, k - d[x - 1] - 1) {
sum = c[tot][i] * a[x - 1][i] % mo * a[m - x + 1][tot - i] % mo;
ans = (ans + sum) % mo;
}
}
int main()
{
// freopen("data.in","r",stdin);
scanf("%lld %lld %lld", &n, &m, &k);
fo(i, 1, n) {
scanf("%lld", &x);
d[x]++;
if (!x) tot++;
}
fo(i, 0, n) c[i][0] = 1;
fo(i, 1, n) {
fo(j, 1, i) c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mo;
}
fo(i, 0, n) a[0][i] = 1;
fo(i, 1, m) {
a[i][0] = 1;
fo(j, 1, n) {
a[i][j] = a[i][j - 1] * (ll)i % mo;
}
}
d[0] = 0;
fo(i, 1, m) d[i] += d[i - 1];
fo(i, 2, m) {
if (d[i - 1] < k) {
solve(i);
}
}
ll inv = power(a[m][tot], mo - 2);
ans=ans*inv%mo;
ans=(ans+1)%mo;
printf("%lld", ans);
return 0;
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
· 【杂谈】分布式事务——高大上的无用知识?