当前位置:网站首页>HDU 4372:Count the Buildings (Stirling数)
HDU 4372:Count the Buildings (Stirling数)
2022-08-10 11:04:00 【51CTO】
Count the Buildings
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1300 Accepted Submission(s): 422
Problem Description
There are N buildings standing in a straight line in the City, numbered from 1 to N. The heights of all the buildings are distinct and between 1 and N. You can see F buildings when you standing in front of the first building and looking forward, and B buildings when you are behind the last building and looking backward. A building can be seen if the building is higher than any building between you and it.
Now, given N, F, B, your task is to figure out how many ways all the buildings can be.
Input
First line of the input is a single integer T (T<=100000), indicating there are T test cases followed.
Next T lines, each line consists of three integer N, F, B, (0<N, F, B<=2000) described above.
Output
For each case, you should output the number of ways mod 1000000007(1e9+7).
Sample Input
Sample Output
2 1
N座高楼,高度均不同且为1~N中的数,从前向后看能看到F个,从后向前看能看到B个,问有多少种可能的排列数。
首先我们知道一个结论:n的环排列的个数与n-1个元素的排列的个数相等,因为P(n,n)/n=(n-1)!。
可以肯定,无论从最左边还是从最右边看,最高的那个楼一定是可以看到的.
假设最高的楼的位置固定,最高楼的编号为n,那么我们为了满足条件,可以在楼n的左边分x-1组,右边分y-1组,且用每
组最高的那个元素代表这一组,那么楼n的左边,从左到右,组与组之间最高的元素一定是单调递增的,且每组中的最高元
素一定排在该组的最左边,每组中的其它元素可以任意排列(相当于这个组中所有元素的环排列)。右边反之亦然。
然后,可以这样考虑这个问题,最高的那个楼左边一定有x-1个组,右边一定有y-1个组,且每组是一个环排列,这就引出
了第一类Stirling数(n个人分成k组,每组内再按特定顺序围圈的分组方法的数目)。
我们可以先把n-1个元素分成x-1+y-1组,然后每组内部做环排列。再在所有组中选取x-1组放到楼n的左边。
所以答案是ans(n, f, b) = C[f + b - 2][f - 1] * S[n - 1][f + b - 2];
AC代码:
边栏推荐
- 力扣练习——56 寻找右区间
- The impact of development mode on testing
- Double.doubleToLongBits() method uses
- 【机器学习】浅谈正规方程法&梯度下降
- Interviewer: How are Dao, Service, Controller, Util, and Model divided in the project?
- CodeChef STMRRG String Merging (dp)
- Kyligence 通过 SOC 2 Type II 审计,以可信赖的企业级产品服务全球客户
- Programmers pursue technology to consolidate basic learning route suggestions
- Mount [shell][mount -o loop]
- 微信小程序,全局变量一个地方改变了其他地方的状态也跟着改变。
猜你喜欢
Memory problems difficult to locate, it is because you do not use ASAN
中小规模网站架构
StoneDB 文档捉虫活动第一季
负载均衡原理分析与源码解读
【勇敢饭饭,不怕刷题之链表】链表倒数节点问题
关于“码农”的一点自嘲解构
ViT结构详解(附pytorch代码)
Pycharm终端出现PS问题、conda或activate不是内部命令问题..
Intel pushes 20220809 CPU microcode update to patch Intel-SA-00657 security vulnerability
Where can I view the version record of WeChat applet submission review history?
随机推荐
HDU 1520 Anniversary party (树型dp)
杭电多校-Loop-(不确定性贪心+线段树)
OSSCore 开源解决方案介绍
GPU accelerated Pinterest recommendation model, the number of parameters increased by 100 times, and the user activity increased by 16%
Mount [shell][mount -o loop]
推荐6个自媒体领域,轻松易上手
MLX90640 红外热成像仪测温传感器 手机 APP 软件 RedEye 连接详细
blocking non-blocking poll mechanism asynchronous
CPU多级缓存与缓存一致性
第2章-矩阵及其运算-矩阵创建(1)
第二十二章 源代码文件 REST API 参考(四)
Module 9 - Designing an e-commerce seckill system
Will SQL and NoSQL eventually converge?
接口定义与实现
HDU 1520 Anniversary party (tree dp)
力扣练习—— 矩形区域不超过 K 的最大数值和(hard)
Double.doubleToLongBits() method uses
2023版揽胜运动曝光,安全、舒适一个不落
【TypeScript】接口类型与类型别名:这两者的用法与区别分别是什么?
2022年裁员潮,失业程序员何去何从?