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 ...
随机推荐
- Promethus+Grafana监控解决方案
[MySQL]企业级监控解决方案Promethus+Grafana Promethus用作监控数据采集与处理,而Grafana只是用作数据展示 一.Promethus简介 Prometheus(普罗米 ...
- vue配置外放generate-asset-webpack-plugin
解决方法:(共有2个方法) 1.借助插件 generate-asset-webpack-plugin .在webpack.prod.conf.js中去生成configServer.json文件,让其 ...
- pidof---找寻PID
pidof---找寻pid 1.根据守护进程找到pid [root@localhost ~]# pidof sshd 2542 1622 [root@localhost ~]# ps -ef | gr ...
- Scala学习十一——操作符
一.本章要点 标识符由字母,数字或运算符构成 一元和二元操作符其实是方法调用 操作符优先级取决于第一个字符,而结合性取决于最后一个字符 apply和update方法在对expr(args)表达式求值时 ...
- 微信小程序上传图片及本地测试
前端(.wxml) <view id="view1"> <view id="btns"> <image id="ima1 ...
- java字符常量
在Java程序中经常会遇到类似于"Hello"这样地字符串,那么这种类型的字符串是Java中是如何存储,下面就说明字符串常量在内存中存储方式: Java程序在编译时会将程序中出现的 ...
- Java List集合深入学习
List: https://blog.csdn.net/qq_37939251/article/details/83499291 https://blog.csdn.net/weixin_403043 ...
- canvas签名
<template> <div class="share" style="background:#fff"> <div class ...
- beego中获取url以及参数的方式
以下都全默认在controller下执行 获取当前请求的referer fmt.Println(this.Ctx.Request.Referer()) 输出:http://localhost:8080 ...
- vim 去掉自动注释和自动回车
取消 :set paste 恢复 :set paste!