本来不想用滚动shuz数组,但是时间太久了,是滚动数组的三倍,内存是两百倍。还有就是学到用函数来进行数据相加与取模。
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ff(a,n) for(int i = 0 ; i < n; i++) scanf("%d",a+i)
#define tp(x) printf("x = %d\n",x)
#define ansp(x) printf("%d\n",x)
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
typedef pair<int,int> pii;
//inline ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&(-x);return res;}
//inline void add(int x,int d){while(x<=n)c[x]+=d,x+=x&(-x);}
//int gcd(int a, int b) { return b == 0 ? a : gcd(b, a%b);}
const ll inf = 0x3f3f3f3f;
const int mx = 0;
int mod,n,m;
int dp[2][85][85];
void add(int &a, ll b){
a = (a+b)%mod;
}
int main(){
// freopen("F:\\in.txt","r",stdin);
int T=10; scanf("%d",&T);
while(T--){
s3(n,m,mod);
int sum = n*m;
mem(dp,0);
dp[0][1][1] = sum;
int now = 0,ne;
for(int k = 2; k <= sum; k++){
ne = now^1;
mem(dp[ne],0);
for(int i = 1; i <= n; i++)
for(int j = 0; j <= m ;j++){
int te = dp[now][i][j];
if(te){
//dp[ne][i][j] += 1LL*(i*j-k+1)*te %mod;
add(dp[ne][i][j],1LL*(i*j-k+1)*te);
//if(dp[ne][i][j]>=mod)
// dp[ne][i][j] -= mod;
// dp[ne][i+1][j] += 1ll*(n-i)*j*te%mod;
add(dp[ne][i+1][j],1ll*(n-i)*j*te);
//if(dp[ne][i+1][j]>=mod)
// dp[ne][i+1][j] -= mod;
//dp[ne][i][j+1] += 1ll*i*(m-j)*te%mod;
add(dp[ne][i][j+1],1ll*i*(m-j)*te);
//if(dp[ne][i][j+1]>=mod)
//dp[ne][i][j+1] -= mod;
}
}
now = ne;
}
printf("%d\n",dp[now][n][m]);
}
return 0;
}