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. 学习《PythonWeb开发实战(董伟明)》中文PDF+源代码

    python可以用了进行数据分析,也可以进行Web开发,一般会使用django或者flask等进行开发. 国内介绍python web的书有写的不错的,推荐看看<PythonWeb开发实战> ...

  2. pandas 6 合并数据 concat, append 垂直合并,数据会变高/长

    from __future__ import print_function import pandas as pd import numpy as np concatenating # ignore ...

  3. 洛谷 P1088 火星人 (全排列)

    直接调用next_permutation即可,向前的话可以调用prev_permutation #include<cstdio> #include<cctype> #inclu ...

  4. 嵌入式(C)笔试题

    1 读程序段,回答问题 (a) int main(int argc,char *argv[]) { int c=9,d=0; c=c++%5; d=c; printf("d=%d\n&quo ...

  5. 【codeforces 404D】Minesweeper 1D

    [题目链接]:http://codeforces.com/problemset/problem/404/D [题意] 让你玩一个1维的扫雷游戏; 游戏的描述由数字0..2以及符号*表示; 分别表示这个 ...

  6. cocos2d-x-3.2 怎样创建新project

    1.在cocos2d-x-3.2\执行python命令 python setup.py //它的作用是将以下这些路径加入到你的用户环境变量中,当然你也能够不加入 COCOS_CONSOLE_ROOT ...

  7. MPI搭建简要教程

    具体安装部署,能够參考 http://www.ibm.com/developerworks/cn/linux/l-cn-mpich2/,该教程将的比較具体. 注:不同版本号的 MPICH2对编译器以及 ...

  8. 配置ssh免密码登录的原理

  9. java9新特性-22-总结

    1.在java 9 中看不到什么? 1.1 一个标准化和轻量级的JSON API 一个标准化和轻量级的JSON API被许多java开发人员所青睐.但是由于资金问题无法在Java 9中见到,但并不会削 ...

  10. python ftp

    #fpt_server.py#__*__ encoding=utf-8 __*__ import socket ,os class MyClass(object): def __init__(self ...