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;
#define int long long
signed main(){
int n,m;
cin >> n >> m;
const int mod=1e9+7;
int DP[n+1][m+1];
for(int j=0;j<=m;j++){
DP[0][j]=1;
}
for(int i=1;i<=n;i++){
for(int j=0;j<=m;j++){
DP[i][j]=0;
if(i>1&&j>0){
DP[i][j]+=(DP[i-2][j-1]*((j*(i-1))%mod));
DP[i][j]%=mod;
}
if(j>1){
DP[i][j]=(DP[i][j]+((DP[i-1][j-2]*((j*(j-1)/2)%mod))%mod));
DP[i][j]%=mod;
}
if(j>0){
DP[i][j]=(DP[i][j]+((4*DP[i-1][j-1]*j)%mod));
DP[i][j]%=mod;
}
DP[i][j]+=DP[i-1][j];
DP[i][j]%=mod;
}
}
cout << (DP[n][m]+mod-1)%mod;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |