Submission #887952

#TimeUsernameProblemLanguageResultExecution timeMemory
887952boris_mihovTents (JOI18_tents)C++17
100 / 100
181 ms78932 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...