Created
October 11, 2016 07:04
-
-
Save asi1024/1a37406a74d1cee7b491405b080f2990 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> | |
#define REP(i,n) for(int i=0;i<(int)(n);i++) | |
#define ALL(x) (x).begin(),(x).end() | |
using namespace std; | |
using ll = long long; | |
const int mod = 1000000007; | |
struct Mod { | |
int n; | |
Mod () : n(0) {;} | |
Mod (int m) : n(m) { | |
if (n >= mod) n %= mod; | |
else if (n < 0) n = (n % mod + mod) % mod; | |
} | |
operator int() { return n; } | |
}; | |
bool operator==(Mod a, Mod b) { return a.n == b.n; } | |
Mod operator+=(Mod &a, Mod b) { a.n += b.n; if (a.n >= mod) a.n -= mod; return a; } | |
Mod operator-=(Mod &a, Mod b) { a.n -= b.n; if (a.n < 0) a.n += mod; return a; } | |
Mod operator*=(Mod &a, Mod b) { a.n = ((long long)a.n * b.n) % mod; return a; } | |
Mod operator+(Mod a, Mod b) { return a += b; } | |
Mod operator-(Mod a, Mod b) { return a -= b; } | |
Mod operator*(Mod a, Mod b) { return a *= b; } | |
Mod operator^(Mod a, int n) { | |
if (n == 0) return Mod(1); | |
Mod res = (a * a) ^ (n / 2); | |
if (n % 2) res = res * a; | |
return res; | |
} | |
ll inv(ll a, ll p) { | |
return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p); | |
} | |
Mod operator/(Mod a, Mod b) { return a * Mod(inv(b, mod)); } | |
#define MAX_N 4096000 | |
Mod fact[MAX_N], factinv[MAX_N]; | |
void init() { | |
fact[0] = Mod(1); factinv[0] = 1; | |
REP(i,MAX_N-1) { | |
fact[i+1] = fact[i] * Mod(i+1); | |
factinv[i+1] = factinv[i] / Mod(i+1); | |
} | |
} | |
Mod comb(int a, int b) { return fact[a] * factinv[b] * factinv[a-b]; } | |
Mod hyper_comb(int a, int b) { | |
if (b == 0) return Mod(a == 0); | |
return comb(a + b - 1, b - 1); | |
} | |
int main() { | |
init(); | |
int A, B, C, Sx, Sy; | |
while (cin >> A >> B >> C >> Sx >> Sy, A + B + C) { | |
Mod res = 0; | |
Mod base = fact[A + B + C] * factinv[A] * factinv[B] * factinv[C]; | |
REP(com, min(Sx, Sy) + 1) { | |
int Awin = Sx - com, Bwin = Sy - com; | |
if (Awin < A || Bwin < B) continue; | |
Mod x = hyper_comb(Awin - A, A); | |
Mod y = hyper_comb(Bwin - B, B); | |
Mod z = hyper_comb(com, A + B + C); | |
res += x * y * z; | |
} | |
cout << res * base << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment