题解:CF2048G Kevin and Matrices
qczrz6v4nhp6u · · 题解
比较有趣的题,但是赛时没时间做了。/ll
Solution
观察一下
所以说上面的条件一定满足左边一定大于等于右边,成立当且仅当
设这个最值为
现在考虑计数。枚举
现在我们有了个
设
复杂度为
Code
#include<bits/stdc++.h>
using namespace std;
using ui=unsigned int;
using ll=long long;
using ull=unsigned long long;
using i128=__int128;
using u128=__uint128_t;
using pii=pair<int,int>;
#define fi first
#define se second
constexpr int N=1e6+5,mod=998244353;
int n,m,v;
inline ll qpow(ll a,ll b){
ll res=1;
for(;b;b>>=1,a=a*a%mod)
if(b&1)res=res*a%mod;
return res;
}
ll fac[N],ifac[N];
void init(int n){
fac[0]=1;
for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i%mod;
ifac[n]=qpow(fac[n],mod-2);
for(int i=n;i>=1;i--)ifac[i-1]=ifac[i]*i%mod;
}
inline ll C(int n,int m){return fac[n]*ifac[m]%mod*ifac[n-m]%mod;}
int main(){
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
init(1e6);
int _Test;cin>>_Test;
while(_Test--){
cin>>n>>m>>v;
ll ans=0;
for(int t=1;t<=v;t++)
for(int i=1;i<=n;i++){
ll A=mod-qpow(v-t+1,n-i),B=qpow(t,i)*qpow(v,n-i)%mod;
ans=(ans+(i&1?mod-1:1)*C(n,i)%mod*(qpow(A+B,m)-qpow(B,m)+mod))%mod;
}
cout<<ans<<'\n';
}
return 0;
}