列表

详情


NC237149. Card

描述

A deck of cards contains C gold coin cards, S prohibition cards and B bomb cards.

Now shuffle the stack randomly and draw cards one by one until the stack is empty or the game is over.

1. If you draw a gold coin card, get it and continue the game.

2. If you draw a prohibition card, end the game.

3. If you draw the bomb card, discard all the gold cards you have obtained and end the game.

Calculate the Expectation of the number of gold coin cards that can be obtained after the game.

输入描述

The input consists of multiple test cases.The first line contains a single integer - the number of test cases. Description of the test cases follows.

each test case contains 3 intergers

输出描述

For each test case, print the expectation, modulo


示例1

输入:

3
3 0 0
1 1 1
10000 10000 10000

输出:

3
166666668
921053954

原站题解

上次编辑到这里,代码来自缓存 点击恢复默认模板

C++ 解法, 执行用时: 4ms, 内存消耗: 464K, 提交时间: 2022-06-05 18:01:17

#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
int kpow(int x,int y,int rex=1){
    for(;y;y>>=1,x=1ll*x*x%mod)if(y&1)rex=1ll*x*rex%mod;
    return rex;
}
void work(){
    int c,s,b;
    cin>>c>>s>>b;
    int x=(s+b)?1ll*s*kpow(s+b,mod-2)%mod:1;
    cout<<1ll*c*kpow(s+b+1,mod-2)%mod*x%mod<<endl;
}
int main(){
    int T;
    cin>>T;
    while(T--)work();
    return 0;
}

上一题