Submission #1021211

#TimeUsernameProblemLanguageResultExecution timeMemory
1021211aufanTents (JOI18_tents)C++17
100 / 100
161 ms71052 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define se second using namespace std; const int mod = 1e9 + 7; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, m; cin >> n >> m; vector<vector<int>> dp(n + 1, vector<int>(m + 1)); for (int i = 0; i <= n; i++) dp[i][0] = 1; for (int i = 0; i <= m; i++) dp[0][i] = 1; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { dp[i][j] += dp[i - 1][j - 1] * j % mod * 4 % mod; dp[i][j] %= mod; if (i - 2 >= 0) { dp[i][j] += dp[i - 2][j - 1] * (i - 1) % mod * j % mod; dp[i][j] %= mod; } if (j - 2 >= 0) { dp[i][j] += dp[i - 1][j - 2] * (j * (j - 1) / 2 % mod) % mod; dp[i][j] %= mod; } dp[i][j] += dp[i - 1][j]; dp[i][j] %= mod; } } dp[n][m] -= 1; dp[n][m] += mod; dp[n][m] %= mod; cout << dp[n][m] << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...