Submission #1033913

#TimeUsernameProblemLanguageResultExecution timeMemory
1033913vjudge1Tents (JOI18_tents)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define int long long #define fi first #define pll pair<long long, long long> #define se second #define isz(a) (int)a.size() using namespace std; const long long inf = 1e18; const int maxn = 3e3 + 5; const int mod = 1e9 + 7; int n, m, divi; int cc[maxn][maxn]; long long binpow(int x, int y){ long long ans = 1; while (y){ if (y & 1) ans = ans * x % mod; x = x * x % mod; y >>= 1; } return ans; } int dp(int i, int j){ if (i < 0 || j < 0) return 0; if (cc[i][j] != -1) return cc[i][j]; int ans = 0; ans += dp(i - 1, j - 2) * i % mod * j % mod * (j - 1) % mod * divi % mod; ans %= mod; ans += dp(i - 2, j - 1) * j % mod * i % mod * (i - 1) % mod * divi % mod; ans %= mod; return cc[i][j] = ans; } void solve(){ cin >> n >> m; for (int i = 1; i <= n; ++i){ for (int j = 1; j <= m; ++j) cc[i][j] = -1; } divi = binpow(2, mod - 2); for (int i = 0; i <= n; ++i) cc[i][0] = 1; for (int i = 0; i <= m; ++i) cc[0][i] = 1; cc[1][1] = 4; cout << dp(n, m) << "\n"; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; // cin >> t; while (t--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...