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>
#define MAXN 307
using namespace std;
long long n,m;
const long long mod=1e9+7;
bool li[MAXN][MAXN][MAXN];
long long dp[MAXN][MAXN][MAXN];
long long dp2[MAXN][MAXN];
bool li2[MAXN][MAXN];
long long ff2(long long n,long long m){
if(m==0)return 1;
if(li2[n][m])return dp2[n][m];
li2[n][m]=true;
dp2[n][m]=ff2(n,m-1);
if(n>=2)dp2[n][m]+=ff2(n-2,m-1)*n*(n-1)/2;
dp2[n][m]%=mod;
return dp2[n][m];
}
long long ff(long long n,long long m,long long e){
if(n==0){
return ff2(e,m);
}
if(li[n][m][e])return dp[n][m][e];
li[n][m][e]=true;
dp[n][m][e]=ff(n-1,m,e+1);
if(m>=1)dp[n][m][e]+=ff(n-1,m-1,e)*m*4;
if(m>=2)dp[n][m][e]+=ff(n-1,m-2,e)*m*(m-1)/2;
dp[n][m][e]%=mod;
return dp[n][m][e];
}
int main(){
cin>>n>>m;
cout<<ff(n,m,0)-1<<"\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |