题目大意
解题思路
设f[i][j]表示一列有i个数,j种颜色的方案数,f[i][j]=f[i-1][j-1]*(p-j+1)+f[i-1][j]*j。g[i][j]表示第i列,j种颜色的方案数,g[i][j]=g[i-1][k]*mat[j][k]。设x表示i,j并集,mat[i][j]=f[n][j]/c[p][j]*c[i][i+j-x]*c[p-i][x-i]。推出矩阵后就可以快速幂。
code
using namespace std;
int const inf=1e9;
int const maxn=100;
int n,m,p,q;
LL f[maxn+10][maxn+10],ni[maxn+10],c[maxn+10][maxn+10],ans[maxn+10][maxn+10],mat[maxn+10][maxn+10],tmp[maxn+10][maxn+10],mod=998244353;
void multansmat(){
fo(i,1,maxn)fo(j,1,maxn)tmp[i][j]=0;
fo(i,1,maxn)fo(j,1,maxn)fo(k,1,maxn)
tmp[i][k]=(tmp[i][k]+ans[i][j]*mat[j][k])%mod;
fo(i,1,maxn)fo(j,1,maxn)ans[i][j]=tmp[i][j];
}
void multmatmat(){
fo(i,1,maxn)fo(j,1,maxn)tmp[i][j]=0;
fo(i,1,maxn)fo(j,1,maxn)fo(k,1,maxn)
tmp[i][k]=(tmp[i][k]+mat[i][j]*mat[j][k])%mod;
fo(i,1,maxn)fo(j,1,maxn)mat[i][j]=tmp[i][j];
}
LL Pow(LL x,LL y){
LL z=1;
for(;y;){
if(y&1)z=(z*x)%mod;
x=(x*x)%mod;
y/=2;
}
return z;
}
int main(){
//freopen("color.in","r",stdin);
//freopen("color.out","w",stdout);
freopen("d.in","r",stdin);
freopen("d.out","w",stdout);
scanf("%d%d%d%d",&n,&m,&p,&q);
fo(i,0,maxn){
c[i][0]=1;
fo(j,1,i)
c[i][j]=(c[i-1][j-1]+c[i-1][j])%mod;
}
fo(i,1,p)ni[i]=Pow(c[p][i],mod-2);
f[0][0]=1;
fo(i,1,n)
fo(j,1,min(i,p))
f[i][j]=(f[i-1][j-1]*(p-j+1)%mod+f[i-1][j]*j%mod)%mod;
fo(i,1,p)
fo(j,1,p){
fo(x,max(q,max(i,j)),min(p,i+j))
mat[i][j]=(mat[i][j]+f[n][j]*ni[j]%mod*c[i][i+j-x]%mod*c[p-i][x-i]%mod)%mod;
//mat[i][j]=(mat[i][j])%mod;
}
fo(i,1,p)ans[1][i]=f[n][i];m--;
for(;m;){
if(m&1)multansmat();
multmatmat();
m/=2;
}
LL anss=0;
fo(i,1,p)anss=(anss+ans[1][i])%mod;
printf("%lld",anss);
return 0;
}