Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4.  
  5. const int MOD = 1e9 + 7;
  6. const int MAXN = 1e6 + 5;
  7.  
  8. ll modpow(ll a, ll b) {
  9. ll res = 1;
  10. while (b) {
  11. if (b&1)
  12. res = (res * a) % MOD;
  13. a = (a * a) % MOD;
  14. b >>= 1;
  15. }
  16. return res;
  17. }
  18.  
  19. ll f[MAXN];
  20. ll invf[MAXN];
  21.  
  22. ll ncr(ll n, ll r) {
  23. if (r == 0 || n == r) return 1;
  24. return (((f[n] * invf[n-r]) % MOD) * invf[r]) % MOD;
  25. }
  26.  
  27. int main() {
  28. int h, w, a, b;
  29. cin >> h >> w >> a >> b;
  30. f[0] = 1;
  31. for (int i = 1; i < MAXN; i++) {
  32. f[i] = (f[i-1] * i) % MOD;
  33. invf[i] = modpow(f[i], MOD-2);
  34. }
  35. ll res = 0;
  36. for (int i = b; i < w; i++) {
  37. int y1 = h - a - 1, x1 = i;
  38. int y2 = a - 1, x2 = w - i - 1;
  39. ll p = (ncr(x1 + y1, x1) * ncr(x2 + y2, x2)) % MOD;
  40. res = (res + p) % MOD;
  41. }
  42. cout << res << '\n';
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement