hdu 4372 Count the Buildings 轮换斯特林数
题目大意
n栋楼有n个不同的高度
现在限制从前面看有F个点,后面看有B个点
分析
最高那栋楼哪都可以看到
剩下的可以最高那栋楼前面分出F-1个组
后面分出B-1个组
每个组的权值定义为组内最高楼的高度
那么\(\binom {F+B-2}{F-1}\)分好组后,组和组之间的顺序是唯一确定的
而且要满足最高楼前面的组,每组最高楼在最左(不然最高楼左边的组内成员能被看到)
在最高楼后面的组同理
确定好每组最高楼后,剩下的楼可以任意排序
又有这样一个结论: (n-1)个点的排列数=n个点的轮换数
那就是在\(n-1\)栋楼中,轮换数为\(F+B-2\)的方案数
\(ans=\dbinom{F+B-2}{F-1}*\left[\begin{matrix} n-1\\F+B-2\end{matrix}\right]\)
注意
数据F+B-2可能越界
solution
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int Q=1000000007;
const int M=2003;
inline LL rd(){
LL x=0;bool f=1;char c=getchar();
for(;!isdigit(c);c=getchar()) if(c=='-') f=0;
for(;isdigit(c);c=getchar()) x=x*10+c-48;
return f?x:-x;
}
int tcas;
LL n,F,B;
LL lh[M][M];
LL c[M][M];
void init(){
int i,j,k;
for(i=0;i<M;i++){
c[i][0]=1;
for(j=1;j<=i;j++)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%Q;
}
lh[0][0]=1;
for(i=1;i<M;i++)
for(j=1;j<=i;j++){
lh[i][j]=(lh[i-1][j-1]+(i-1)*lh[i-1][j]%Q)%Q;
}
}
int main(){
init();
int i;
tcas=rd();
while(tcas--){
n=rd(),F=rd(),B=rd();
if(F+B-2>=M) puts("0");
else printf("%I64d\n",c[F+B-2][F-1]*lh[n-1][F+B-2]%Q);
}
return 0;
}
hdu 4372 Count the Buildings 轮换斯特林数的更多相关文章
- HDU 4372 Count the Buildings——第一类斯特林数
题目大意:n幢楼,从左边能看见f幢楼,右边能看见b幢楼 楼高是1~n的排列. 问楼的可能情况 把握看到楼的本质! 最高的一定能看见! 计数问题要向组合数学或者dp靠拢.但是这个题询问又很多,难以dp ...
- HDU 4372 Count the Buildings [第一类斯特林数]
有n(<=2000)栋楼排成一排,高度恰好是1至n且两两不同.现在从左侧看能看到f栋,从右边看能看到b栋,问有多少种可能方案. T组数据, (T<=100000) 自己只想出了用DP搞 发 ...
- 【HDU 4372】 Count the Buildings (第一类斯特林数)
Count the Buildings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- hdu 4372 Count the Buildings —— 思路+第一类斯特林数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4372 首先,最高的会被看见: 然后考虑剩下 \( x+y-2 \) 个被看见的,每个带了一群被它挡住的楼, ...
- HDU 4372 Count the Buildings
Count the Buildings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- hdu 3625 Examining the Rooms 轮换斯特林数
题目大意 n个房间对应n把钥匙 每个房间的钥匙随机放在某个房间内,概率相同. 有K次炸门的机会,求能进入所有房间的概率 一号门不给你炸 分析 我们设\(key_i\)为第i间房里的钥匙是哪把 视作房间 ...
- HDU 4372 Count the Buildings:第一类Stirling数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4372 题意: 有n栋高楼横着排成一排,各自的高度为1到n的一个排列. 从左边看可以看到f栋楼,从右边看 ...
- HDU 4372 - Count the Buildings(组合计数)
首先想过n^3的组合方法,即f(i,j,k)=f(i-1,j,k)*(i-2)+f(i-1,j-1,k)+f(i-1,j,k-1),肯定搞不定 然后想了好久没有效果,就去逛大神博客了,结果发现需要用到 ...
- HDU 4372 Count the Buildings 组合数学
题意:有n个点上可能有楼房,从前面可以看到x栋楼,从后面可以看到y栋,问楼的位置有多少种可能. 印象中好像做过这个题,
随机推荐
- PAT (Basic Level) Practise (中文)- 1013. 数素数 (20)
http://www.patest.cn/contests/pat-b-practise/1013 令Pi表示第i个素数.现任给两个正整数M <= N <= 104,请输出PM到PN的所有 ...
- 课下作业04-2String的使用方法
1.动手动脑之String.equals()方法public class StringEquals { public static void main(String[] args) { String ...
- TCP/IP协议头部结构体
TCP/IP协议头部结构体(转) 网络协议结构体定义 // i386 is little_endian. #ifndef LITTLE_ENDIAN #define LITTLE_ENDIAN (1) ...
- ANSI C 与 K&R C
C语言由Dennis M.Ritchie在1973年设计和实现.从那以后使用者逐渐增加.到1978年Ritchie和Bell实验室的另一位程序专家Kernighan合写了著名的<TheC Pro ...
- Applied Nonparametric Statistics-lec7
Ref: https://onlinecourses.science.psu.edu/stat464/print/book/export/html/9 经过前面的步骤,我们已经可以判断几个样本之间是否 ...
- Linux数据库忘记密码-修改方法
一.拥有原来的myql的root的密码: 方法一:在mysql系统外,使用mysqladmin# mysqladmin -u root -p password "test123"E ...
- selenium2-元素管理方式及解析
1.管理文件格式:yaml 2.Yaml里面的内容格式: 3.格式说明: baidu_input后面接上":",直接回车,然后空两格 type与value这两个key是固定 ...
- Android自动化测试如何获取坐标点?
有以下三种方法: 1.打开开发者选项中的“显示指针位置”: 英文文版本为Settings->Developer option->Show touches(on)->Pointer l ...
- Hadoop4.2HDFS测试报告之一
1.1 测试方案 1.1.1 测试目标 为了验证本地文件系统和HDFS存储能力对比,将1G文件组存储进各个文件系统,记录存储任务消耗的时间. l 测试HDFS的高可用性和高稳定性 l 测试 ...
- CodeForces 8D Two Friends 判断三个圆相交
题意: 有两个人\(Alan\)和\(Bob\),他们现在都在\(A\)点,现在\(Bob\)想去\(B\)点,\(Alan\)想先到\(C\)点再去\(B\)点. \(Alan\)所走的总路程不能超 ...