题目大意

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 轮换斯特林数的更多相关文章

  1. HDU 4372 Count the Buildings——第一类斯特林数

    题目大意:n幢楼,从左边能看见f幢楼,右边能看见b幢楼 楼高是1~n的排列. 问楼的可能情况 把握看到楼的本质! 最高的一定能看见! 计数问题要向组合数学或者dp靠拢.但是这个题询问又很多,难以dp ...

  2. HDU 4372 Count the Buildings [第一类斯特林数]

    有n(<=2000)栋楼排成一排,高度恰好是1至n且两两不同.现在从左侧看能看到f栋,从右边看能看到b栋,问有多少种可能方案. T组数据, (T<=100000) 自己只想出了用DP搞 发 ...

  3. 【HDU 4372】 Count the Buildings (第一类斯特林数)

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  4. hdu 4372 Count the Buildings —— 思路+第一类斯特林数

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4372 首先,最高的会被看见: 然后考虑剩下 \( x+y-2 \) 个被看见的,每个带了一群被它挡住的楼, ...

  5. HDU 4372 Count the Buildings

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  6. hdu 3625 Examining the Rooms 轮换斯特林数

    题目大意 n个房间对应n把钥匙 每个房间的钥匙随机放在某个房间内,概率相同. 有K次炸门的机会,求能进入所有房间的概率 一号门不给你炸 分析 我们设\(key_i\)为第i间房里的钥匙是哪把 视作房间 ...

  7. HDU 4372 Count the Buildings:第一类Stirling数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4372 题意: 有n栋高楼横着排成一排,各自的高度为1到n的一个排列. 从左边看可以看到f栋楼,从右边看 ...

  8. 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),肯定搞不定 然后想了好久没有效果,就去逛大神博客了,结果发现需要用到 ...

  9. HDU 4372 Count the Buildings 组合数学

    题意:有n个点上可能有楼房,从前面可以看到x栋楼,从后面可以看到y栋,问楼的位置有多少种可能. 印象中好像做过这个题,

随机推荐

  1. 学习笔记(五): Feature Crosses

    目录 Feature Crosses Encoding Nonlinearity Kinds of feature crosses Glossay Crossing One-Hot Vectors P ...

  2. pandas关联mysql并读写数据库

    1.代码读写mysql,必须安装关联mysql的工具 操作如下命令: sudo apt-get install mysql-server mysql-clientsudo apt-get instal ...

  3. 2-python基础

    1.第一个程序 新建一个python文件,然后写上代码,运行即可 print("hello world") 2.变量 变量就是存东西,供后面来用的 变量名只能是 字母.数字或下划线 ...

  4. 【Shiro】调用doGetAuthenticationInfo进行认证成功之后,isAuthenticated是false的问题。

    使用@Configuration配置shiro无状态登录时出现的问题,在subject.login之后当前线程重新绑定了一个假定subject,isAuthenticated. 这里自定义的访问拦截器 ...

  5. json_encode() 避免转换中文

    json_encode() 避免转换中文 我们都知道,json_encode()可以将数据转换为json格式,而且只针对utf8编码的数据有效,而且在转换中文的时候,将中文转换成不可读的”\u***” ...

  6. Python 成长之路

    Python roadmap python 基础 ... 内置常用函数.三元运算.递归 迭代器和生成器 模块和常用的模块 面向对象 对向对象进阶 网络编程 并发编程 ... 数据库 MySQL pym ...

  7. LeetCode(260) Single Number III

    题目 Given an array of numbers nums, in which exactly two elements appear only once and all the other ...

  8. 安装openstack同步数据库时出错解决方法

    错误提示:(2003, "Can't connect to MySQL server on 'controller' ([Errno -2] Name or service not know ...

  9. noip2017行记

    前奏 写了所有的变量名在linux下测,结果发现并没什么用...听说将所有的变量加上下划线,加上自己的名字作为前缀.. lgj,“感觉今年有网络流,今年要立个flag”,zjr“你咋不上天儿” 在车上 ...

  10. iOS启动图 LaunchImage LaunchScreen.xib

    1.Images.xcassets添加LaunchImage 2.具体大小和添加类别都是可以调的 640*960   (4/4s)                                 2X ...