一开始看成最多值班三天了,柿子推出来发现不对,看半天才发现看错题了。
这题最多值 天班的话我建议降绿。
如果有能值三天班的踹我一脚。
想到 DP,设 表示前 个老师,工作总量为 时的方案数,那么易得转移方程式
其中, 表示一个老师工作量为 时的方案数。
考虑如何求 。由题目得,这 的工作量会被分成 段(如果是奇数的话就无解了),那么就相当于在剩下的 个数中插入 段,每段要至少隔一天,插板法得方案数为 ,但是由于 ,所以无法预处理,但是可以 求出。为了减小转移时的时间复杂度,先预处理记录下来即可。
时间复杂度 。
要先对关于 的数取模防止爆 long long。
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, s, t) for (int i = s; i <= t; i++)
#define pre(i, s, t) for (int i = s; i >= t; i--)
namespace OI {
#ifdef _WIN32
#define gc _getchar_nolock
#define pc _putchar_nolock
#else
#define gc getchar_unlocked
#define pc putchar_unlocked
#endif
inline int rd() {
int x = 0, f = 1; char c = gc();
while (!isdigit(c)) { if (c == '-') f = -1; c = gc(); }
while (isdigit(c)) x = (x << 3) + (x << 1) + c - '0', c = gc();
return x * f;
}
inline void wt(int x) {
if (x == 0) return pc('0'), void();
if (x < 0) pc('-'), x = -x;
string str;
while (x) str.push_back(x % 10 + '0'), x /= 10;
pre(i, str.size() - 1, 0) pc(str[i]);
}
inline void wt(string str) { for (char &c : str) pc(c); }
}
using namespace OI;
const int N = 805, MD = 998244353;
int n, m, K, f[N], g[N], c[N], inv[N], fac[N], invf[N];
int C(int x, int y) { // C^x_y
if (y < x) return 0;
int res = 1;
rep(i, y - x + 1, y) res = res * (i % MD) % MD;
rep(i, 1, x) res = res * inv[i] % MD;
return res;
}
inline void sol() {
n = rd(), m = rd(), K = rd();
rep(i, 2, K) {
if (i & 1) continue;
c[i] = C(i / 2, n - i + 1) % MD;
}
fill(f + 1, f + K + 1, 0), f[0] = 1;
rep(i, 1, m) {
rep(j, 0, K) g[j] = 0;
rep(j, 2, K) rep(k, 0, j - 2) g[j] = (g[j] + f[k] * c[j - k]) % MD;
rep(j, 0, K) f[j] = g[j];
}
wt(f[K]), wt("\n");
}
signed main() {
int _ = rd(); inv[1] = 1, fac[0] = 1, invf[0] = 1;
rep(i, 2, 800) inv[i] = (MD - MD / i) * inv[MD % i] % MD;
rep(i, 1, 800) fac[i] = fac[i - 1] * i % MD, invf[i] = invf[i - 1] * inv[i] % MD;
while (_--) sol();
return 0;
}