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;
template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl
using ll = long long;
const int maxn = 3001;
const ll mod = 1e9 + 7;
void add(ll& x, ll y) {
if (x>=mod) x%=mod;
if (y>=mod) y%=mod;
x += y;
if (x>=mod) x%=mod;
}
int n,m;
ll dp[maxn][maxn];
ll choose2(ll x) {
return x*(x-1)/2;
}
ll f(int i, int j) {
if (i==0 || j==0) return 1;
ll &res = dp[i][j];
if (~res) return res;
res = 0;
add(res, f(i-1,j));
add(res, 4ll*j*f(i-1,j-1));
if (j>=2) add(res, choose2(j)*f(i-1,j-2));
if (i>=2) add(res, 1ll*j*(i-1)*f(i-2,j-1));
return res;
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin>>n>>m;
memset(dp,-1,sizeof(dp));
ll res = f(n,m);
res--;
res%=mod;
res+=mod;
res%=mod;
cout<<res<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |