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;
long long dp1(long long x,long long rem);
const int N=3003,mod=1e9+7;
int n,m;
long long memo[N][N],memo1[N][N];
long long dp (long long x,long long rem)
{
if (x==m)
{
return (rem!=n);
}
long long &ret= memo[x][rem];
if (ret)
return ret;
ret= dp(x+1,rem);
if (rem>=2)
{
ret+= dp(x+1,rem-2)*(rem*(rem-1)/2);
ret%=mod;
}
if (rem>=1)
{
ret+= dp(x+1,rem-1)*rem*4;
ret%=mod;
if (x+2<=m)
{
ret+= (dp(x+2,rem-1)*rem*(m-x-1));
ret%=mod;
}
}
return ret;
}
int main()
{
cin >>n>>m;
cout <<dp(0,n);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |