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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
const int MD = 1e9 + 7;
int F[3001][3001];
int add(int x, int y) {
if ((x += y) >= MD) {
x -= MD;
}
if (x < 0) {
x += MD;
}
return x;
}
int C2(int N) {
return N * (N - 1) / 2;
}
int dp(int i, int j) {
if (i < 0 || j < 0) {
return 0;
}
if (i == 0) {
return 1;
}
if (~F[i][j]) {
return F[i][j];
}
int &res = F[i][j];
res = 0;
res = add(res, dp(i - 1, j));
res = add(res, (long long) dp(i - 1, j - 2) * C2(j) % MD);
res = add(res, (long long) dp(i - 1, j - 1) * 4 % MD * j % MD);
res = add(res, (long long) dp(i - 2, j - 1) * (i - 1) % MD * j % MD);
return res;
}
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int N, M; cin >> N >> M;
memset(F, -1, sizeof(F));
cout << add(dp(N, M), -1);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |