题解:P16949 「LAOI-18」矩阵浪潮
Solution
神题,非常有意思。
显然
我们考虑
那么我们就需要给球一个限制让他只能放在
下面我们回到原式
Code
#include<iostream>
#define int long long
using namespace std;
int n,m;
const int mod=998244353;
int ksm(int a,int b){
int ans=1;
a%=mod;
while(b){
if(b%2){
b--;
ans*=a;
ans%=mod;
}
b/=2;
a*=a;
a%=mod;
}
return ans;
}
int T;
signed main(){
cin>>T;
while(T--){
cin>>n>>m;
cout<<m%mod*ksm(m-1,n-1)%mod<<endl;
}
}