#include <bits/stdc++.h>
#define int long long
using namespace std;
int a,b;
int f[3005][3005];
int mod =1e9+7;
int dp(int i,int j){
if (i<0 || j<0){
return 0;
}
if (i==0 || j==0){
return 1;
}
if (f[i][j]!=-1){
return f[i][j];
}
f[i][j]=0;
f[i][j] = (f[i][j] + (dp(i-1,j-2)*j*(j-1)/2 + dp(i-2,j-1)*(i-1)*j)%mod )%mod;
f[i][j] = (f[i][j]+ (dp(i-1,j-1) + (dp(i-1,j-1)*4*j)%mod))%mod;
return f[i][j];
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> a >> b;
for (int i=1;i<=a;i++){
for (int j=1;j<=b;j++){
f[i][j]=-1;
}
}
cout << dp(a,b)-1;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |