제출 #47520

#제출 시각아이디문제언어결과실행 시간메모리
47520qoo2p5Tents (JOI18_tents)C++17
100 / 100
559 ms71420 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int INF = (int) 1e9 + 1e6 + 123;
const ll LINF = (ll) 1e18 + 1e9 + 123;

#define rep(i, s, t) for (auto i = (s); i < (t); ++(i))
#define per(i, s, t) for (auto i = (s); i >= (t); --(i))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back

bool mini(auto &x, const auto &y) {
    if (y < x) {
        x = y;
        return 1;
    }
    return 0;
}

bool maxi(auto &x, const auto &y) {
    if (y > x) {
        x = y;
        return 1;
    }
    return 0;
}

void run();

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
    return 0;
}

const ll MOD = (ll) 1e9 + 7;

ll power(ll x, ll y) {
    if (y == 0) {
        return 1;
    }
    if (y % 2 == 0) {
        ll t = power(x, y / 2);
        return t * t % MOD;
    } else {
        return power(x, y - 1) * x % MOD;
    }
}

const int N = 3003;

int H, W;
ll g[N];
ll f[N][N];
ll fact[N], rfact[N];

ll cnk(int n, int k) {
    if (k > n) {
        return 0;
    }
    return fact[n] * rfact[n - k] % MOD * rfact[k] % MOD;
}

ll dp[N][N];

ll get(int w, int h) {
    if (w < 0 || h < 0) {
        return 0;
    }
    return dp[w][h];
}

void run() {
    fact[0] = 1;
    rep(i, 1, N) {
        fact[i] = fact[i - 1] * i % MOD;
    }
    rep(i, 0, N) {
        rfact[i] = power(fact[i], MOD - 2);
    }
    
    dp[0][0] = 1;
    rep(w, 1, N) {
        rep(h, 1, N) {
            ll res = get(w - 2, h - 1) * cnk(w, 2) % MOD;
            res = (res + 4 * w * get(w - 1, h - 1) % MOD) % MOD;
            res = (res + w * (h - 1) * get(w - 1, h - 2) % MOD) % MOD;
            dp[w][h] = res;
        }
    }
    
    ll ans = 0;
    cin >> H >> W;
    rep(h, 1, H + 1) {
        rep(w, 1, W + 1) {
            ans = (ans + get(w, h) * cnk(W, w) % MOD * cnk(H, h) % MOD) % MOD;
        }
    }
    
    cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...