#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int HALF = 5e8 + 4;
int exp(int a, int b) {
return (b?1LL*exp(1LL*a*a%MOD,b/2)*(b&1?a:1)%MOD:1);
}
int solve(int h, int c) {
int fact[6005], invfact[6005];
fact[0] = invfact[0] = 1;
for(int i=1;i<6005;i++) {
fact[i] = 1LL * fact[i-1] * i % MOD;
invfact[i] = exp(fact[i], MOD-2);
}
int ans = MOD - 1;
for(int x=0;x<=2*min(h,c);x+=2)
for(int y=0;y<=min(x/2,h+c-x);y++)
ans = (ans + 1LL * fact[h] * fact[c] % MOD * fact[h + c - x] % MOD * invfact[h - x/2] % MOD * invfact[c - x/2] % MOD * invfact[x/2 - y] % MOD * invfact[y] % MOD * invfact[h+c-x-y] % MOD * exp(2, x - 3 * y + MOD - 1) % MOD) % MOD;
return ans;
}
int main() {
int h, c;
cin >> h >> c;
cout << solve(h, c);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |