Created
February 17, 2017 14:25
-
-
Save takageymt/95f4367fd5ecc9b499331cc7996c7dac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define int long long | |
#define all(v) begin(v), end(v) | |
#define rep(i, n) for(int i = 0; i < (int)(n); i++) | |
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++) | |
#define min(...) min({__VA_ARGS__}) | |
#define max(...) max({__VA_ARGS__}) | |
const int inf = 1LL << 55; | |
#define MAX_N 1002020 | |
typedef long long int64; | |
const int64 mod = 1e9 + 7; | |
inline int64 extgcd(int64 a, int64 b, int64 &x, int64 &y) | |
{ | |
int64 d = a; | |
if(b != 0) d = extgcd(b, a % b, y, x), y -= (a / b) * x; | |
else x = 1, y = 0; | |
return d; | |
} | |
inline int64 modPow(int64 x, int64 n) | |
{ | |
if(n == 0) return 1; | |
int64 ret = modPow(x, n/2); | |
(ret *= ret) %= mod; | |
if(n & 1) (ret *= x) %= mod; | |
return ret; | |
} | |
inline int64 modInv(int64 a) | |
{ | |
return modPow(a, mod - 2); | |
} | |
inline int64 modFact(int n) | |
{ | |
int64 ret = 1; | |
while(n > 1) (ret *= n--) %= mod; | |
return ret; | |
} | |
inline int64 modComb(int64 n, int64 r) | |
{ | |
static int64 fact[MAX_N], invfact[MAX_N]; | |
if(fact[0] == 0) { | |
fact[0] = invfact[0] = 1; | |
for(int i = 1; i < MAX_N; i++) { | |
fact[i] = fact[i-1] * i % mod; | |
invfact[i] = modInv(fact[i]); | |
} | |
} | |
if(r < 0 || n < r) return 0; | |
return fact[n] * invfact[r] % mod * invfact[n-r] % mod; | |
} | |
signed main() | |
{ | |
cin.tie(0); | |
ios_base::sync_with_stdio(0); | |
cout << fixed << setprecision(12); | |
int h, w, a, b; | |
cin >> h >> w >> a >> b; | |
int ans = 0; | |
reps(i, b, w) { | |
int x = modComb(i+h-a-1, i) % mod; | |
int y = modComb(w-i-1+a-1, a-1) % mod; | |
(ans += (x*y)%mod) %= mod; | |
} | |
cout << ans << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment