【HDU4372】Count the Buildings (第一类斯特林数)
Description
$N$座高楼,高度均不同且为$1~N$中的数,从前向后看能看到$F$个,从后向前看能看到$B$个,问有多少种可能的排列数。
$T$组询问,答案模$1000000007$。其中$n\leq 2000,T\leq 100000$
题解:
可以考虑现将最高的拿出来,那么可以考虑左边需要有$F-1$个房子成递增关系,那么可以将左边的房子分成$F-1$个组,右边有$B-1$个房子成递减关系,也是如此。
不禁想到第一类斯特林数,$s(p,k)$是将将$p$个物体排成$k$个非空循环排列的方法数($k$个排列是有先后顺序的)。
可以想到,每一组都是有顺序的(与环等价,每组把最高的转到第一个,每组再按第一个排序,右边同理,普通排序不能保证只有F个递增,B个递减)。
除此之外,还要计算组合数,就是在$(F-1+B-1)$组中取出$F-1$个到左边,乘上即是答案。
CODE:
#include<iostream>
#include<cstdio>
using namespace std; #define mod 1000000007
int T,N,F,B;
long long c[][];
long long s[][]; void init(){
c[][]=s[][]=;
for(int i=;i<=;i++){
s[i][]=;
c[i][]=;
for(int j=;j<=i;j++){
s[i][j]=((i-)*s[i-][j]+s[i-][j-])%mod;
c[i][j]=( c[i-][j]+c[i-][j-])%mod;
}
}
} int main(){
init();
scanf("%d",&T);
while(T--){
scanf("%d%d%d",&N,&F,&B);
printf("%d\n",s[N-][F+B-]*c[F+B-][F-]%mod);
}
}
【HDU4372】Count the Buildings (第一类斯特林数)的更多相关文章
- 【HDU 4372】 Count the Buildings (第一类斯特林数)
Count the Buildings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- HDU 4372 Count the Buildings——第一类斯特林数
题目大意:n幢楼,从左边能看见f幢楼,右边能看见b幢楼 楼高是1~n的排列. 问楼的可能情况 把握看到楼的本质! 最高的一定能看见! 计数问题要向组合数学或者dp靠拢.但是这个题询问又很多,难以dp ...
- HDU 4372 Count the Buildings [第一类斯特林数]
有n(<=2000)栋楼排成一排,高度恰好是1至n且两两不同.现在从左侧看能看到f栋,从右边看能看到b栋,问有多少种可能方案. T组数据, (T<=100000) 自己只想出了用DP搞 发 ...
- hdu 4372 Count the Buildings 轮换斯特林数
题目大意 n栋楼有n个不同的高度 现在限制从前面看有F个点,后面看有B个点 分析 最高那栋楼哪都可以看到 剩下的可以最高那栋楼前面分出F-1个组 后面分出B-1个组 每个组的权值定义为组内最高楼的高度 ...
- HDU4372 Count the Buildings —— 组合数 + 第一类斯特林数
题目链接:https://vjudge.net/problem/HDU-4372 Count the Buildings Time Limit: 2000/1000 MS (Java/Others) ...
- HDU4372 Count the Buildings (+题解:斯特林数)
题面 (笔者翻译) There are N buildings standing in a straight line in the City, numbered from 1 to N. The h ...
- hdu 4372 Count the Buildings —— 思路+第一类斯特林数
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4372 首先,最高的会被看见: 然后考虑剩下 \( x+y-2 \) 个被看见的,每个带了一群被它挡住的楼, ...
- [Hdu4372] Count the Buildings
[Hdu4372] Count the Buildings Description There are N buildings standing in a straight line in the C ...
- 【组合数学:第一类斯特林数】【HDU3625】Examining the Rooms
Examining the Rooms Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
随机推荐
- javaweb基础(16)_jsp指令
一.JSP指令简介 JSP指令(directive)是为JSP引擎而设计的,它们并不直接产生任何可见输出,而只是告诉引擎如何处理JSP页面中的其余部分. 在JSP 2.0规范中共定义了三个指令: pa ...
- A. Vitya in the Countryside
A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...
- 【dp】饥饿的牛
普通dp题 题目描述 牛在饲料槽前排好了队.饲料槽依次用1到n(1 ≤ n ≤ 2000)编号.每天晚上,一头幸运的牛根据约翰的规则,吃其中一些槽里的饲料. 约翰提供b个区间的清单.一个区间是一对整数 ...
- NodeJS基础-Buffer
Buffer用于处理二进制数据流 实例类似于整数数组,大小固定 C++代码在V8堆外分配物理内存 // 创建一个长度为10,且用0填充的Buffer const buf1 = Buffer.alloc ...
- python入门:if、elif、else 条件语句的基本用法
#!/usr/bin/env python # -*- coding:utf-8 -*- #elif(否则如果,译音:埃尔夫)eise(否则,译音:埃尔斯) #if.elif.else 条件语句的基本 ...
- MyBatis的mapper.xml文件的参数问题:org.apache.ibatis.builder.IncompleteElementException: Could not find parameter map
配置参数类型有两种选择,即:parameterType和parameterMap 不管参数是否是基本数据类型还是map类型,都是使用parameterType. 版权声明:本文为博主原创文章,未经博主 ...
- thinkcmf5 模板版变量的加载过程 和 新增网站配置项怎么全局使用
1.模板全局配置是怎么加载的 在 HomeBaseController.php 的 fech方法 $more = $this->getThemeFileMore($template); ...
- 【nginx】 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream
2013/10/22 20:05:49 [error] 12691#0: *6 FastCGI sent in stderr: "Primary script unknown" w ...
- 第6章 AOP与全局异常处理6.5-6.11 慕课网微信小程序开发学习笔记
https://coding.imooc.com/learn/list/97.html 目录: 第6章 AOP与全局异常处理6-1 正确理解异常处理流程 13:236-2 固有的处理异常的思维模式与流 ...
- 字符串-POJ3974-Palindrome
Palindrome Time Limit: 15000MS Memory Limit: 65536K Description Andy the smart computer science stud ...