组合数学的题目,很明显这个题目的难点在于重塔的设定,所以一定要从重塔下手,但是一直因为一个误区没找到办法。
题解的办法,先枚举有两个重塔的行和列,再枚举独占行列的塔中的重塔数量。
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int maxn=2e2+9,mod=1e9+7;
int n,m,p,q;
long long pp[maxn][maxn];
long long c[maxn][maxn];
long long a[maxn][maxn];
long long getpp(int m,int k)
{
if(pp[m][k]) return pp[m][k];
else if(k==0) return pp[m][k]=1;
else if(k==1) return pp[m][k]=m*(m-1)/2;
else return pp[m][k]=(m*(m-1)/2*getpp(m-2,k-1))%mod;
}
long long getc(int n,int k)
{
if(c[n][k]) return c[n][k];
else if(n==k) return c[n][k]=1;
else if(k==0) return c[n][k]=1;
else if(k==1) return c[n][k]=n;
else return c[n][k]=(getc(n-1,k-1)+getc(n-1,k))%mod;
}
long long cal(int n,int m,int k)
{
long long ret=(getc(n,k)*getpp(m,k))%mod;
return ret;
}
long long geta(int n,int k)
{
if(a[n][k]) return a[n][k];
else if(k==0) return a[n][k]=1;
else if(k==1) return a[n][k]=n;
else return a[n][k]=(geta(n-1,k-1)*n)%mod;
}
long long cc[maxn][maxn][maxn];
void getcc()
{
for(int i=0;i<=200;i++)
for(int j=0;j<=200;j++)
for(int k=1;k<=i&&k<=j;k++)
cc[i][j][k]=(getc(i,k)*geta(j,k))%mod;
for(int i=0;i<=200;i++)
for(int j=0;j<=200;j++)
cc[i][j][0]=1;
for(int i=0;i<=200;i++)
for(int j=0;j<=200;j++)
for(int k=1;k<=200;k++)
cc[i][j][k]=(cc[i][j][k]+cc[i][j][k-1])%mod;
}
int main()
{
getcc();
// freopen("in.txt","r",stdin);
int T;
scanf("%d",&T);
while(T--)
{
long long ans=0,tmp,txt;
scanf("%d%d%d%d",&n,&m,&q,&p);
for(int i=0;i<=q;i++)
for(int j=0;(i+j<<1)<=q;j++)
{
int nn=n-i-2*j;
int mm=m-j-2*i;
if(nn<0||mm<0) continue;
tmp=(cal(n,m,i)*cal(m-i*2,n-i,j))%mod;
for(int k=0;k+(i+j)*2<=q&&k<=min(nn,mm);k++)
{
txt=((getc(nn,k)*geta(mm,k)%mod)*cc[nn-k][mm-k][p])%mod;;
ans=(ans+(txt*tmp)%mod)%mod;
}
}
cout<<ans-1<<endl;
}
return 0;
}