This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
const int maxn=3000+10;
long long fact[maxn],revfact[maxn],mp[maxn];
long long mod=1e9+7;
long long mypow(long long m,long long y){
if(y==0){
return 1;
}
long long p=mypow(m,(y>>1));
p*=p;
p%=mod;
if(y&1){
p*=m;
p%=mod;
}
return p;
}
void aval(){
fact[0]=1;
for(int i=1;i<maxn;i++){
fact[i]=fact[i-1]*i;
fact[i]%=mod;
}
revfact[maxn-1]=mypow(fact[maxn-1],mod-2);
for(int i=maxn-2;i>=0;i--){
revfact[i]=revfact[i+1]*(i+1)%mod;
}
mp[0]=1;
for(int i=1;i<maxn;i++){
mp[i]=mp[i-1]*4%mod;
}
}
long long dp[maxn][maxn];
long long c(int i,int j){
if(i<0||j<0||j>i){
return 0;
}
long long ret=fact[i]*revfact[j]%mod*revfact[i-j]%mod;
return ret;
}
long long pre[maxn];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n,m;
cin>>n>>m;
aval();
//cout<<"whhat "<<c(2,2)<<'\n';
for(int i=0;i<=n;i++){
for(int j=0;j<=m;j++){
if(i==0){
dp[i][j]=1;
continue;
}
if(j==0){
dp[i][j]=0;
continue;
}
dp[i][j]=dp[i-1][j-1]*j%mod*4%mod;
if(i>=2){
dp[i][j]+=dp[i-2][j-1]*j%mod*(i-1)%mod;
}
dp[i][j]%=mod;
}
}
pre[0]=1;
for(int i=1;i*2<=m;i++){
pre[i]=pre[i-1];
pre[i]*=c(m-(i-1)*2,2);
pre[i]%=mod;
}
long long res=0;
for(int i=0;i<=n&&i*2<=m;i++){
for(int j=0;j+i<=n;j++){
if(i+j==0){
continue;
}
long long fake=c(n,i)*c(n-i,j)%mod*pre[i]%mod*dp[j][m-i*2]%mod;
//cout<<i<<" "<<j<<" "<<c(n,i)<<" "<<c(n-i,j)<<" "<<pre[i]<<" "<<dp[j][m-i*2]<<" "<<fake<<"\n";
res+=fake;
}
}
res%=mod;
cout<<res<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |