List likes playing card 公式~
Problem: List likes playing card
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?".
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).
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).
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; }
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从二进制到误差:逐行拆解C语言浮点运算中的4008175468544之谜
· .NET制作智能桌面机器人:结合BotSharp智能体框架开发语音交互
· 软件产品开发中常见的10个问题及处理方法
· .NET 原生驾驭 AI 新基建实战系列:向量数据库的应用与畅想
· 从问题排查到源码分析:ActiveMQ消费端频繁日志刷屏的秘密
· C# 13 中的新增功能实操
· Ollama本地部署大模型总结
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(4)
· langchain0.3教程:从0到1打造一个智能聊天机器人
· 2025成都.NET开发者Connect圆满结束