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 N=3005;
long long dp[N][N];
int n,m;
long long mod=1e9+7;
long long bt(int i, int j)
{
if(i==n)
{
if(j==m)
return 0;
return 1;
}
if(dp[i][j]!=-1)
return dp[i][j];
long long x=bt(i+1,j);
x%=mod;
if(j)
x+=bt(i+1,j-1)*4*j;
x%=mod;
if(j&&i+2<=n)
x+=bt(i+2,j-1)*j*(n-i-1);
x%=mod;
if(j>1)
x+=((bt(i+1,j-2)*j*(j-1))/2)%mod;
x%=mod;
dp[i][j]=x;
return x;
}
int main()
{
cin>>n>>m;
memset(dp,-1,sizeof dp);
cout<<bt(0,m)<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |