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 <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
typedef long long llong;
const int MAXN = 3000 + 10;
const int MOD = 1e9 + 7;
llong dp[MAXN][MAXN];
bool bl[MAXN][MAXN];
llong rec(int n, int m)
{
if (n < 0 || m < 0)
{
return 0;
}
if (n == 0 || m == 0)
{
return 1;
}
if (bl[n][m])
{
return dp[n][m];
}
bl[n][m] = true;
dp[n][m] = rec(n - 1, m);
dp[n][m] += 4 * rec(n - 1, m - 1) * m;
dp[n][m] += rec(n - 1, m - 2) * m * (m - 1) / 2;
dp[n][m] += rec(n - 2, m - 1) * m * (n - 1);
dp[n][m] %= MOD;
return dp[n][m];
}
int n, m;
int main()
{
std::cin >> n >> m;
std::cout << rec(n, m) - 1 << '\n';
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |