题目大意

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. 《队长说得队》【Alpha】Scrum meeting 5

    项目 内容 这个作业属于哪个课程 >>2016级计算机科学与工程学院软件工程(西北师范大学) 这个作业的要求在哪里 >>实验十二 团队作业8:软件测试与ALPHA冲刺 团队名称 ...

  2. java基础—GUI编程(二)

    一.事件监听

  3. springmvc的第一个程序

    文中用的框架版本:spring 3,hibernate 3,没有的,自己上网下. web.xml配置: <?xml version="1.0" encoding=" ...

  4. Java 吃金币游戏设计与制作,下载版后补,代码没问题

    package com.swift; import java.awt.Color; import java.awt.Point; import java.awt.event.KeyEvent; imp ...

  5. vue 点击下拉框

    data: { hide:false, zhi:"全部" }, <div class="item"> <div class="c2c ...

  6. 学习笔记(二):使用 TensorFlow 的起始步骤(First Steps with TensorFlow)

    目录 1.工具包 TensorFlow 张量 (Tensor) 图 (graph) TensorBoard 2.tf.estimator API Estimator 预创建的 Estimator (p ...

  7. PHP计算两个日期相差的年月日时分秒

    $start_time = '2017-09-06 15:12:20'; $end_time = '2018-09-08 10:20:45'; get_time($start_time,$end_ti ...

  8. ubuntu16.04安装mongodb,创建数据库管理员,上传文件到服务器上

    1.导入软件源得公钥 sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927 2.为mongodb创建软件 ...

  9. Voyager的路由

    修改默认的后台登录路由 打开web.php,把prefix值改为你想设置的值,如back: Route::group(['prefix' => 'back'], function () { Vo ...

  10. MySQL中文转换成拼音的函数

    CREATE DEFINER=`root`@`localhost` FUNCTION `fristPinyin`(`P_NAME` VARCHAR(255) CHARSET utf8) RETURNS ...