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