#include <bits/stdc++.h>
// #include <ext/rope>
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
using namespace std;
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define bit(mask, i) ((mask >> i) & 1)
#define el '\n'
#define F first
#define S second
template <class X, class Y> bool maximize(X &x, const Y &y) { return (x < y ? x = y, 1 : 0); }
template <class X, class Y> bool minimize(X &x, const Y &y) { return (x > y ? x = y, 1 : 0); }
const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = 1e9 + 7;
const int MULTI = 0;
const ld eps = 1e-9;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0}; // R D L U
const int ddx[4] = {-1, 1, 1, -1}, ddy[4] = {1, 1, -1, -1}; // UR DR DL UL
const char cx[4] = {'R', 'D', 'L', 'U'};
const ll base = 31;
const int nMOD = 2;
const ll mods[] = {(ll)1e9 + 10777, (ll)1e9 + 19777, (ll)1e9 + 3, (ll)1e9 + 3777};
const int N = 3e3 + 5;
int h, w, dp[N][N], f[N][N], g[N][N];
int fac[N], ifac[N];
int binpow(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = 1LL * res * a % MOD;
a = 1LL * a * a % MOD;
b >>= 1;
}
return res;
}
void precalc() {
fac[0] = 1;
for (int i = 1; i < N; ++i)
fac[i] = 1LL * fac[i - 1] * i % MOD;
ifac[N - 1] = binpow(fac[N - 1], MOD - 2);
for (int i = N - 2; i >= 0; --i)
ifac[i] = 1LL * ifac[i + 1] * (i + 1) % MOD;
}
int C(int n, int k) {
if (n < k) return 0;
return 1LL * fac[n] * ifac[k] % MOD * ifac[n - k] % MOD;
}
void solve() {
cin >> h >> w;
precalc();
for (int i = 0; i <= w; ++i) {
f[i][0] = 1;
for (int j = 1; j <= min(h, i / 2); ++j)
f[i][j] = 1LL * f[i][j - 1] * C(i - 2 * (j - 1), 2) % MOD;
}
for (int i = 0; i <= h; ++i) {
g[i][0] = 1;
for (int j = 1; j <= min(w, i / 2); ++j)
g[i][j] = 1LL * g[i][j - 1] * C(i - 2 * (j - 1), 2) % MOD;
}
for (int i = 1; i <= h; ++i)
for (int j = 1; j <= w; ++j) {
dp[i][j] = (dp[i - 1][j] + 1LL * j * 4 % MOD * ((i == 1 || j == 1) ? 1 : dp[i - 1][j - 1]) % MOD) % MOD;
if (i > 1 && j > 1) (dp[i][j] += 4 * j) %= MOD;
}
int res = 0;
for (int row2 = 0; row2 <= min(h, w / 2); ++row2) {
int comb = C(h, row2);
comb = 1LL * comb * f[w][row2] % MOD;
int tmp = comb;
for (int col2 = 0; col2 <= min(w - 2 * row2, (h - row2) / 2); ++col2) {
comb = 1LL * comb * C(w - 2 * row2, col2) % MOD;
comb = 1LL * comb * g[h - row2][col2] % MOD;
int remain_h = h - row2 - 2 * col2;
int remain_w = w - col2 - 2 * row2;
if (remain_h && remain_w) {
if (remain_h < h || remain_w < w)
(res += comb) %= MOD;
comb = 1LL * comb * dp[remain_h][remain_w] % MOD;
}
(res += comb) %= MOD;
comb = tmp;
}
}
cout << res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (!MULTI) solve();
else {
int test; cin >> test;
while (test--) solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |