题解:
更新:
k=1的时候要乘n
代码:
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e3+5;
typedef long long ll;
typedef pair<int,int> PII;
int T;
int n,m,mod;
int fac[N][N];
int dp[N][N];
int per[N];
int power(int a,int b)
{
int res=1;
while(b)
{
if(b%2==1) res=res*a%mod;
a=a*a%mod;
b/=2;
}
return res;
}
void solve()
{
cin>>n>>m>>mod;
for(int i=0;i<=5002;i++)
{
fac[i][i]=1;
fac[i][0]=1;
}
per[0]=1;
for(int i=1;i<=5002;i++) per[i]=(per[i-1]*2)%mod;
for(int i=1;i<=5001;i++)
{
for(int j=1;j<=i;j++)
{
fac[i][j]=(fac[i-1][j-1]%mod+fac[i-1][j]%mod)%mod;
}
}
int ans=0;
for(int i=1;i<=n;i++)
{
int k1=power(2,(n-i)*(m-1)%mod)%mod;
int k2=power(2,i%mod);
k2=power((k2+mod-1)%mod,(m-1)%mod);
ans=(ans+fac[n][i]*k1%mod*k2%mod)%mod;
}
int ansA=ans%mod;//A题答案
int ansB2=power(2,(n-1)*(m-1)%mod)%mod*n%mod;
dp[0][0]=1;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m-1;j++)
{
dp[i][j]=i*(dp[i][j-1]+dp[i-1][j-1])%mod;
}
}
int ansB1=0;
//cout<<ansA<<endl;
int cur1=1;
for(int k=n;k>=2;k--)
{
int cur=1;
int kk=(per[k]-k-1+10*mod)%mod;
for(int t=m-1;t>=k;t--)
{
int res=((fac[n][k]*cur1%mod)*(fac[m-1][t]*cur%mod))%mod*dp[k][t]%mod;
cur=(cur*kk)%mod;
ansB1=(ansB1+res)%mod;
//cout<<res<<endl;
}
cur1=(cur1*per[m-1])%mod;
}
int ansB=(ansB1+ansB2)%mod;
cout<<(ansA-ansB+mod)%mod<<endl;
}
signed main()
{
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
T=1;
//cin>>T;
while(T--)
{
solve();
}
return 0;
}