Submission #866559

#TimeUsernameProblemLanguageResultExecution timeMemory
866559ArashJafariyanTents (JOI18_tents)C++17
100 / 100
133 ms36232 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3e3 + 4, MOD = 1e9 + 7; int n, m, _dp[N][N]; int dp(int i, int j) { if (i < 0 || j < 0) return 0; else if (!i || !j) return 1; else return _dp[i][j]; } int c(int k) { return k * (k - 1) / 2; } int main() { ios::sync_with_stdio(0); cin.tie(0); for (int i = 1; i < N; ++i) { for (int j = 1; j < N; ++j) { _dp[i][j] = dp(i, j - 1); _dp[i][j] = (_dp[i][j] + 4ll * i * dp(i - 1, j - 1) % MOD) % MOD; _dp[i][j] = (_dp[i][j] + 1ll * c(i) * dp(i - 2, j - 1) % MOD) % MOD; _dp[i][j] = (_dp[i][j] + 1ll * i * (j - 1) * dp(i - 1, j - 2) % MOD) % MOD; } } cin >> n >> m; cout << (dp(n, m) + MOD - 1) % MOD; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...