public class DoubleLive {
final int MOD = 1000 * 1000 * 1000 + 7;
long my_pow(long a, long b) {
long r = 1;
while(b > 0) {
if(b % 2 == 1) r = r * a % MOD;
a = a * a % MOD;
b /= 2;
}
return r;
}
long my_inv(long a) { return my_pow(a, MOD - 2); }
public int findEV(int B, int H, int T) {
System.
out.
println(480 * my_inv
(7) % MOD
); long p[][][] = new long[2][B+1][H+B+1];
p[0][B][H] = 1;
long answer = 0;
long memo_inv[] = new long[2*B+H+1];
for(int i = 1; i <= 2 * B + H; ++i)
memo_inv[i] = my_inv(i);
for(int firstBearWounded = 0; firstBearWounded <= 1; ++firstBearWounded)
for(int twos = B; twos >= 0; --twos)
for(int ones = H+B; ones >= 1; --ones) {
long my_p = p[firstBearWounded][twos][ones];
if(my_p == 0) continue;
int alive = twos + ones;
if(2 * B + H - (2 * twos + ones) == T) {
answer = (answer + my_p * alive) % MOD;
continue;
}
my_p = my_p * memo_inv[alive] % MOD;
// a single dies
int a = ones - 1;
if(firstBearWounded == 1) --a;
if(a >= 1) {
p[firstBearWounded][twos][ones-1] += my_p * a;
p[firstBearWounded][twos][ones-1] %= MOD;
}
// a double becomes a single
a = twos;
if(firstBearWounded == 0) --a;
if(a >= 1) {
p[firstBearWounded][twos-1][ones+1] += my_p * a;
p[firstBearWounded][twos-1][ones+1] %= MOD;
}
// the fixed bear gets wounded
if(firstBearWounded == 0) {
p[1][twos-1][ones+1] += my_p;
p[1][twos-1][ones+1] %= MOD;
}
}
answer = answer * B % MOD * H % MOD;
return (int) answer;
}
}