zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    SSL延迟有多大?(转)
    Nginx/LVS/HAProxy负载均衡软件的优缺点详解(转)
    lvs、haproxy、nginx 负载均衡的比较分析(转)
    入木三分学网络第一篇--VRRP协议详解第一篇(转)
    从一个开发的角度看负载均衡和LVS(转)
    四层和七层负载均衡的区别(转)
    geo实现方案
    HTTP API 设计指南(转)
    app后端设计(0)--总目录(转)
    Django接收自定义http header(转)
  • 原文地址:https://www.cnblogs.com/cshg/p/6582661.html
Copyright © 2011-2022 走看看