이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |