CF2048G Kevin and Matrices
没打这场,赛后做了下 EFG,E 用时 1h,F 用时 5min(仅口胡),G 用时 2h,怎么回事呢?
对题面进行翻译,发现一个矩阵合法当且仅当 存在至少一个位置,既是所在行最大值又是所在列最小值,称这样的位置是好的。
注意到如果存在两个好的位置
那么这说明我们可以使用两个集合
直接计算倒闭了,但是我们把
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int P = 998244353, N = 1e6;
ll fac[1000005], ifac[1000005];
ll C(int n, int m) {
return fac[n] * ifac[m] % P * ifac[n - m] % P;
}
ll QPow(ll a, ll b) {
ll res = 1;
for (; b; b >>= 1, a = a * a % P) if (b & 1) res = res * a % P;
return res;
}
int T, n, m, V;
int main() {
scanf("%d", &T);
fac[0] = 1;
for (int i = 1; i <= N; i++) fac[i] = fac[i - 1] * i % P;
ifac[N] = QPow(fac[N], P - 2);
for (int i = N; i; i--) ifac[i - 1] = ifac[i] * i % P;
while (T--) {
scanf("%d%d%d", &n, &m, &V);
ll ans = 0;
for (int x = 1; x <= n; x++) {
for (int c = 1; c <= V; c++) {
ll t = 1ll * ((x & 1) ? P - 1 : 1) * C(n, x) % P * QPow(QPow(c, x), m) % P * QPow(QPow(V, n - x), m) % P;
ll w = QPow(c, 1ll * x * (P - 2)) * (P - 1) % P * QPow(V - c + 1, n - x) % P * QPow(V, 1ll * (n - x) * (P - 2)) % P;
ans += t * QPow(w + 1, m) % P;
ans -= t;
}
}
printf("%lld\n", (ans % P + P) % P);
}
return 0;
}