ABC – 042 – D – Iroha and a Grid(排列組合)
阿新 • • 發佈:2021-01-06
技術標籤:組合數學
https://abc042.contest.atcoder.jp/tasks/arc058_b?lang=en
由於左下角有禁區,所以左上角到右下角的路徑分為兩段,一段從左上角到禁區的上面那一行,一段從禁區的上面那一行到右下角,然後求和即可,這題是用來儲存組合數取模模板的。
ll quickpow(ll x, int k)
{
ll res = 1;
while(k){
if(k & 1) res = (res * x) % mod;
k >>= 1, x = (x * x) % mod;
}
return res;
}
ll fac[200005] = {1};
ll C(int n, int m){return (fac[n] * quickpow((fac[m] * fac[n - m]) % mod, mod - 2)) % mod;}
const int maxn = 1e5 + 5;
int main()
{
for (int i = 1; i < 200005; ++i) fac[i] = (fac[i - 1] * i) % mod;
int h, w, a, b;
h = in(); w = in(); a = in(); b = in();
ll ans = 0;
for (int i = b + 1; i <= w; ++i)
ans = (ans + C(i - 1 + h - a - 1, min(i, h - a) - 1) * C(w - i + a - 1, min(w - i, a - 1))) % mod;
outn(ans);
return 0;
}