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?\n");
        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\n", ans);
    }
    return 0;
}
复制代码

 

posted on   disppr  阅读(265)  评论(0编辑  收藏  举报

编辑推荐:
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
阅读排行:
· C# 13 中的新增功能实操
· Ollama本地部署大模型总结
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(4)
· langchain0.3教程:从0到1打造一个智能聊天机器人
· 2025成都.NET开发者Connect圆满结束
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示