List likes playing card 公式~

Problem: List likes playing card

Time limit: 2s     Mem limit: 64 MB     
Problem Description

List's father morejarphone likes playing poker with List very much. Now List has a deck of playing card, consisting of a black cards and b red cards. List shuffles the cards randomly, puts them on the desk and tells morejarphone to do the following operations:

1. taking away one card randomly;

2. checking the color of it, if it is black, repeats the operations until he take a red one or there are no cards left, else stops.

Now List wants to know the mathematical expectation of the cards morejarphone takes away in total. To avoid the float number, you should multiply the answer by (a+b)!  then mod 1e9+7. If morejarphone can't take red card, output "List, are you kidding me?".

Input

The first of the input is an integer t (t<=100), which is the number of the cases.

Next t line, each line contains two numbers: a and b (1<=a+b<=1e6).

Output

For each case, output "Case #x: y"(without quota), where x is their number of the cases and y is the answer.  If morejarphone can't take red card, output "List, are you kidding me?"(without quota).

Sample Input
3 1 1 2 0 2 33
Sample Output
Case #1: 3 Case #2: List, are you kidding me? Case #3: 15385176
Source

2016-11东北大学组队赛

可以推出求期望的E = ∑{ 1<= i <= a+1} (a+b-i)! * b*i*b!/(b+1-i)!

/*可以忽略我的求组合数的模板

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
typedef long long int LL;
const int p = 1e9+7;
const int mod = 1e9+7;
const int MAXN = 1e6+4;
LL quick_mod(LL a, LL b) {
    LL ans = 1;
    a %= p;
    while(b) {
        if(b & 1) {
            ans = ans * a % p;
        }
        b >>= 1;
        a = a * a % p;
    }
    return ans;
}
LL f[MAXN], inv[MAXN];

void init(int n) {
    f[0] = inv[0] = 1;
    for(int i = 1; i <= n; i++) f[i] = f[i-1]*i%mod;
    inv[n] = quick_mod(f[n], mod-2);
    for(int i = n-1; i >= 1; i--) inv[i] = inv[i+1]*(i+1)%mod;
}

int main() {
    init(1000000);
    int T, a, b, cas = 0;
    scanf("%d", &T);
    while(T--){
        scanf("%d%d", &a, &b);
        printf("Case #%d: ", ++cas);
        if(b == 0) {
        printf("List, are you kidding me?
");
        continue;
        }
        LL ans = 0;
        LL add = a, gg = 1;
        for(int i = 1; i <= a+1; i++){
            ans += 1LL*b*i%mod*f[a+b-i]%mod*gg%mod;
            ans %= p;
            gg = gg*add%mod;
            add --;
        }
       printf("%lld
", ans);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/cshg/p/6582661.html