-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathD.cpp
More file actions
44 lines (37 loc) · 892 Bytes
/
Copy pathD.cpp
File metadata and controls
44 lines (37 loc) · 892 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
#include <algorithm>
using namespace std;
const long long mod = 1e9 + 7ll;
const int N = 2 * 1e5 + 10;
long long fac[N];
long long pw(long long a, long long b){
if ( b == 0ll ) return 1ll;
long long r = pw(a, b/2ll);
r = (r * r) % mod;
if (b % 2ll) r = (a * r) % mod;
return r;
}
long long inv(long long x){
return pw(x, mod - 2ll);
}
long long path(long long a, long long b) {
long long ans = fac[a + b];
ans = (ans * inv(fac[a])) % mod;
ans = (ans * inv(fac[b])) % mod;
return ans;
}
int main () {
int h, w, a, b;
cin >> h >> w >> a >> b;
fac[0] = 1ll;
for ( int i=1 ; i<N ; i++){
fac[i] = (i * fac[i-1]) % mod;
}
long long ans = 0ll;
for (int i=h-a, j=b+1 ; i>0 && j<=w ; i--, j++) {
ans += (path(i-1, j-1) * path(h-i, w-j)) % mod;
}
ans = (ans % mod + mod) % mod;
cout << ans;
return 0;
}