Count the Buildings

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2521    Accepted Submission(s):
817

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
2
3 2 2
3 2 1
 
Sample Output
2
1
 
Source
 
Recommend
zhuyuanchen520   |   We have carefully selected several
similar problems for you:  4059 2819 1730 2176 1850 
 
 
实在搞不懂HDU的脾气啊。
为什么交G++会RE????
这道题的话。
不管是从左边看还是从右边看,视线总是会被中间最高的给挡住
所以我们把左边和右边分组来看。
对于某一边,我们确定出能够看见的楼房,那么不能够看见的楼房就可以任意排列
我们把能看见的楼房,与下一个能看到的楼房(不包括下一个楼房)之间的楼看为一组
那么组内的元素就可以任意排,假设一组有$n$个楼房,那么它们自由排列的方案数就是$(n-1)!$
这会让你联想的到什么?
哈哈没错,第一类斯特灵数(神TM能想到)
这样我们就可以首先对所有的楼房进行分组,然后再让他们自由排列
一共有$F-1+B-1$组
 
#include<iostream>
#include<cstdio>
#define LL long long
using namespace std;
const LL MAXN=*1e6+;
LL T,N,F,B;
LL mod=;
LL c[][],s[][];
int main()
{
for(LL i=;i<=;i++)
{
c[i][]=;
c[i][i]=;
s[i][]=;//无法频出环
s[i][i]=;//只能拼出一个环
for(LL j=;j<i;j++)
c[i][j]=(c[i-][j-]%mod+c[i-][j]%mod)%mod,
s[i][j]=(s[i-][j-]%mod+(i-)%mod*s[i-][j]%mod)%mod;
}
scanf("%I64d",&T);
while(T--)
{
scanf("%I64d%I64d%I64d",&N,&F,&B);
printf("%I64d\n",(c[F-+B-][F-]%mod*s[N-][F-+B-]%mod)%mod);
}
return ;
}
 
 
 
 

HDU 4372 Count the Buildings的更多相关文章

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

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

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

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

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

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

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

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

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

  6. hdu 4372 Count the Buildings 轮换斯特林数

    题目大意 n栋楼有n个不同的高度 现在限制从前面看有F个点,后面看有B个点 分析 最高那栋楼哪都可以看到 剩下的可以最高那栋楼前面分出F-1个组 后面分出B-1个组 每个组的权值定义为组内最高楼的高度 ...

  7. HDU 4372 Count the Buildings 组合数学

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

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

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

  9. [Hdu4372] Count the Buildings

    [Hdu4372] Count the Buildings Description There are N buildings standing in a straight line in the C ...

随机推荐

  1. thinkphp 5.0整合phpsocketio完整攻略,绕坑

    使用环境: thinkphp5.0 项目需求 前端下单,后台接受,并立即做出提示.例如:美团外卖,客户端下单成功后,商家端就会立即有接单语音提示. 开发环境 thinkphp5.0 phpsocket ...

  2. nyoj33 蛇形填数

    蛇形填数 时间限制:3000 ms  |  内存限制:65535 KB 难度:3 描写叙述 在n*n方陈里填入1,2,...,n*n,要求填成蛇形.比如n=4时方陈为: 10 11 12 1 9 16 ...

  3. [AngularJS] ng-ture-value & ng-false-value

    When you have a checkbox, not necessary that just 'ture' & 'false', you might have 'yes', 'no', ...

  4. 响应http报文中的Date属性与cookie过期时间的关系

    今天在測试.net时,发现一个莫名其妙的问题:cookie老是保存不到浏览器端; 经过细致的比对成功与不成功的报文,居然无意中发现好像Date与它有关系,这太让我意想不到了,从来不知道cookie保存 ...

  5. Android之Http通信——1.初识Http协议

    Android之Http通信--1.初识Http协议 引言: 今天是六一儿童节,先在这里给各位超龄儿童说声节日快乐哈~( ╯□╰ ),小猪也象征性地给群里的小朋友们派了红包-嗯,忙碌的五月最终过去了, ...

  6. WPF-MVVM-Demo

    MVVM The model-view-viewmodel is a typically WPF pattern. It consists of a view that gets all the us ...

  7. kali 2.0 linux中的Nmap的主机探测

    不多说,直接上干货! 如果是第一次接触Nmap,推荐在MSF终端中输入不加任何参数的Nmap命令,以查看其使用方法. 更多,其实, msf > nmap -h [*] exec: nmap -h ...

  8. java9新特性-8-语法改进:钻石操作符(Diamond Operator)使用升级

    1.使用说明 我们将能够与匿名实现类共同使用钻石操作符(diamond operator) 在java8中如下的操作是会报错的:   编译报错信息:'<>' cannot be used ...

  9. Android-Context的一切

    Context类型 我们知道,Android应用都是使用Java语言来编写的,那么大家可以思考一下,一个Android程序和一个Java程序,他们最大的区别在哪里?划分界限又是什么呢?其实简单点分析, ...

  10. 使用 Beego 搭建 Restful API 项目

    1 环境准备 首先你需要在你的环境安装以下软件: go:编程语言运行环境 git:版本控制工具 beego:go 语言流行的开发框架 bee:beego 配套的快速搭建工具 你喜欢的数据库:这里以 M ...