HDU 4372 Count the Buildings
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
2012 Multi-University Training Contest 8
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=2*1e6+10;
LL T,N,F,B;
LL mod=1000000007;
LL c[2011][2011],s[2011][2011];
int main()
{
for(LL i=0;i<=2010;i++)
{
c[i][0]=1;
c[i][i]=1;
s[i][0]=0;//无法频出环
s[i][i]=1;//只能拼出一个环
for(LL j=1;j<i;j++)
c[i][j]=(c[i-1][j-1]%mod+c[i-1][j]%mod)%mod,
s[i][j]=(s[i-1][j-1]%mod+(i-1)%mod*s[i-1][j]%mod)%mod;
}
scanf("%I64d",&T);
while(T--)
{
scanf("%I64d%I64d%I64d",&N,&F,&B);
printf("%I64dn",(c[F-1+B-1][F-1]%mod*s[N-1][F-1+B-1]%mod)%mod);
}
return 0;
}
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- leetcode-easy-array-最大子序和
- Leecode No.3 无重复字符的最长子串
- Solidity 0.6.11 更新
- 潘石屹用Python解决100个问题 | 最小公倍数
- 通过CREATE2获得合约地址:解决交易所充值账号问题
- 小知识:如何判定crontab任务的执行频度
- 以太坊合约静态分析工具Slither简介与使用
- Cesium第一次搭建环境出不来地球的问题
- 小知识:解决EXP-00003的报错
- Mysql5中Packet for query is too large (3396053 > 1048576),数据量太大解决方案
- 关于 servlet 的这个问题,你能答对吗?
- MYSQL数据优化常用配置参数
- Hadoop分块存储解析及还原分块存储的文件
- ValueError: too many values to unpack (expected 2)
- VMware15更新后克隆Centos7发现网卡起不来了