Count the Buildings ( s1 )
http://acm.hdu.edu.cn/showproblem.php?pid=4372
题意:n个房子在一条线上(n<=2000),高度分别为1~n,现在需要将房子这样放置:从最左往右能看到F个房子,从最右往左能看到B个房子,能看到的条件是 两者之间的房子都要低于这个房子。问这样的方案数。
思路: 额,这个东西呢,想通了也就 很简单的啦。
n座塔,高度分别1~n,那 那个最高的不就从哪边看 都是能被看到的吗,我们就假设它的位置是固定的咯,我们假设这个最高的为塔n。 然后咧,题目要求 塔n的左边至少要有 f - 1 个递增的塔嘛,,右边就是 至少 b - 1 个 递减的啦,递增递减其实没什么所谓啦,知道是单调的就行了。 然后咧,我们 就 把 剩下的 n - 1 个数 分组 然后咧,分成 f - 1 + b - 1组, 然后就是 每组 至少一个元素,然后多的话呢,就用这组最高的塔 表示这一组 的高度。 然后咧,就 从 这 f - 1 + b - 1 个组中,取 f - 1 个放到 塔n的左边(组合数) 乘起来就是答案了。额, n - 1 个数,分成 f - 1 + b - 1 的组, 那么 肯定能 保证 每个组的高度都是不一样的,那么 对于任意的 f - 1组,总存在唯一的 或者是单调递增的排列,或者是递减的排列。 对于剩下的 b - 1 组也是如此。 然后那个分组的其实就是 第一类 斯特林数 啦
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#define LL long long
#define ULL unsigned long long
#define rep(i,j,k) for(int i=j;i<=k;i++)
#define dep(i,j,k) for(int i=k;i>=j;i--)
#define INF 0x3f3f3f3f
#define mem(i,j) memset(i,j,sizeof(i))
#define make(i,j) make_pair(i,j)
#define pb push_back
using namespace std;
const int N = ;
const int mod = ;
LL c[N][N];
LL s1[N][N];
void init() {
c[][] = ;
rep(i, , N - ) {
c[i][] = c[i][i] = ;
s1[i][] = ; s1[i][i] = ;
rep(j, , i - ) {
c[i][j] = (c[i - ][j] % mod + c[i - ][j - ] % mod) % mod;
s1[i][j] =( (i - ) % mod * s1[i - ][j] % mod + s1[i - ][j - ] % mod ) % mod;
}
}
}
int main() {
init();
int t;
int n, f, b;
scanf("%d", &t);
while(t--) {
scanf("%d %d %d", &n, &f, &b);
if( f + b - > ) { puts(""); continue ; } ///你不特胖,那你就和我一起re三遍吧
LL ans = c[f + b - ][f - ] % mod * s1[n - ][f + b - ] % mod;
cout << ans <<endl;
}
return ;
}
Count the Buildings ( s1 )的更多相关文章
- 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(组合计数)
首先想过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),肯定搞不定 然后想了好久没有效果,就去逛大神博客了,结果发现需要用到 ...
- 【HDU4372】Count the Buildings (第一类斯特林数)
Description $N$座高楼,高度均不同且为$1~N$中的数,从前向后看能看到$F$个,从后向前看能看到$B$个,问有多少种可能的排列数. $T$组询问,答案模$1000000007$.其中$ ...
- CF451D Count Good Substrings (DP)
Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...
- 2017年上海金马五校程序设计竞赛:Problem C : Count the Number (模拟)
Description Given n numbers, your task is to insert '+' or '-' in front of each number to construct ...
- 【leetcode】Count and Say (easy)
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
- hdu 4296 Buildings(贪婪)
主题链接:http://acm.hdu.edu.cn/showproblem.php? pid=4296 Buildings Time Limit: 5000/2000 MS (Java/Others ...
- mysql练习----SUM and COUNT/zh图(二)
世界国家概况 GROUP BY 和 HAVING 通过包括一个GROUP BY子句功能, SUM并将COUNT 其应用于共享值的项目组.当你指定 GROUP BY continent 结果是每个不同的 ...
- Leetcode 之Count and Say(35)
很有意思的一道题,不好想啊. string getNext(string &s) { ]; ; stringstream ss; ; i < s.size(); i++) { if (s ...
随机推荐
- Web前端开发CSS基础
CSS 层叠样式表(英文全称:Cascading Style Sheets),是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言.CSS不 ...
- golang 客户端
package main import ( "fmt" "io/ioutil" "net/http" ) func main() { fmt ...
- 转SSL/TLS协议
TLS名为传输层安全协议(Transport Layer Protocol),这个协议是一套加密的通信协议.它的前身是SSL协议(安全套接层协议,Secure Sockets Layer).这两个协议 ...
- 手把手教你搭建FastDFS集群(上)
手把手教你搭建FastDFS集群(上) 本文链接:https://blog.csdn.net/u012453843/article/details/68957209 FastDFS是一个 ...
- C++ const关键字以及static关键字
const可以用来修饰类中的成员函数以及成员变量以及类的对象 1.const修饰成员函数: 该函数是只读函数,不允许修改任何成员变量,但是可以使用类中的任何成员变量: 不允许修改任何非static的类 ...
- pthread 笔记
1.创建线程 res = pthread_create(&a_thread, NULL, thread_function1, NULL); if (res != 0) { perror(&qu ...
- element-ui 中日期控件限制时间跨度
支持点击今天及之前任意日期,前后跨度不超过31天,且不超过今天 <el-date-picker v-model="searchForm.dateRange" type=&qu ...
- JVM学习(三):垃圾回收算法
局部性原理和分代回收思想 大学学习操作系统或者计算机组成原理的时候都提到一个重要概念,叫局部性原理. 局部性原理是指CPU访问存储器时,无论是存取指令还是存取数据,所访问的存储单元都趋于聚集在一个较小 ...
- 解决IDEA报错Could not autowire. There is more than one bean of 'xxx' type
更新项目之后IDEA突然出现了这样的报错信息.显示Could not autowire. There is more than one bean of 'xxx' type.这个错误的意思是xxx类型 ...
- django 使用mysql数据库
一 修改settings里面的配置文件 import pymysql # 一定要添加这两行!通过pip install pymysql! 或者pycharm 里面安装 pymysql.install_ ...