Count the Buildings
K - Count the Buildings
参考:Count the Buildings
思路可以借鉴,但是代码略有问题
写的时候 re 了 9 发,然后把变量定义的顺序换了一下居然 A 了,以为这个是个骚操作,最后才发现是真的会越界,当 f+b>n+2 的时候就有可能会发生越界,而这种情况,if 判断一下就好
代码:
// Created by CAD on 2019/8/17.
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod=1000000007;
const int maxn=2010;
ll c[maxn][maxn],s[maxn][maxn];
int main()
{
memset(s, 0, sizeof(s));
memset(c, 0, sizeof(c));
s[0][0]=1;
for (int i=0; i<=maxn-10; ++i) c[i][0]=1;
for (int i=1; i<=maxn-10; ++i)
for (int j=1; j<=maxn-10; ++j){
s[i][j]=(s[i-1][j-1]+(i-1)*s[i-1][j])%mod;
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
int t; scanf("%d", &t);
while (t--){
int n,f,b;
scanf("%d%d%d",&n,&f,&b);
if(f+b>n+2) cout<<0<<endl;
else printf("%lld\n",(s[n-1][f+b-2]*c[f+b-2][f-1])%mod);
}
return 0;
}
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 ...
- [Hdu4372] Count the Buildings
[Hdu4372] Count the Buildings Description There are N buildings standing in a straight line in the C ...
- HDU4372 Count the Buildings —— 组合数 + 第一类斯特林数
题目链接:https://vjudge.net/problem/HDU-4372 Count the Buildings Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 4372 Count the Buildings
Count the Buildings Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- 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:第一类Stirling数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4372 题意: 有n栋高楼横着排成一排,各自的高度为1到n的一个排列. 从左边看可以看到f栋楼,从右边看 ...
- HDU 4372 Count the Buildings [第一类斯特林数]
有n(<=2000)栋楼排成一排,高度恰好是1至n且两两不同.现在从左侧看能看到f栋,从右边看能看到b栋,问有多少种可能方案. T组数据, (T<=100000) 自己只想出了用DP搞 发 ...
- HDU 4372 Count the Buildings——第一类斯特林数
题目大意:n幢楼,从左边能看见f幢楼,右边能看见b幢楼 楼高是1~n的排列. 问楼的可能情况 把握看到楼的本质! 最高的一定能看见! 计数问题要向组合数学或者dp靠拢.但是这个题询问又很多,难以dp ...
- 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),肯定搞不定 然后想了好久没有效果,就去逛大神博客了,结果发现需要用到 ...
随机推荐
- Invalid property value
又见这个错误!头几天同事遇到这个问题,我查到去年写的并按此解决了,原文在这里,查了半天,才查出是ftShortInt造成的这个错误. 当我们在设计期将ClientQuery.Active设置为True ...
- (转)JVM垃圾回收机制
一.技术背景 GC的历史比Java久远,早在1960年Lisp这门语言中就使用了内存动态分配和垃圾回收技术 二.那些内存需要回收? JVM的内存结构包括五大区域:程序计数器.虚拟机栈.本地方法栈.堆区 ...
- Delphi 画刷与作图区域
樊伟胜
- NORDIC 修改MTU
https://www.cnblogs.com/jiangjiu/p/10063556.html 注意要修改RAM起始地址,因为MTU增大了
- mmu(虚拟地址和物理地址简单图解)
- Linux用户组管理及用户权限2
用户.组和权限管理 Multi-tasks,Multi-Users,多任务,多用户的计算机 每个使用者: 用户标识.密码: Authentication ...
- 如何在GitBook中使用Git管理
1.在GitBook中新建[Book],找到对应目录下的位置,拷贝[book]名称后删除文件夹以及文件,新建文件夹重命名为[book]名称 2.打开文件夹,在根目录下选择创建git仓库,即 git i ...
- Satellite-Hacking 攻击卫星/卫星安全
虽说卫星安全这种东西也是高富帅才玩得起的领域,但是了解了解总是没坏处.参考了一些资料,如果想详细了解可以戳进去看看.看了这么多资料,总结一下吧. Why? 卫星存在安全问题主要有一下俩原因,首先是成本 ...
- java8学习之Lambda表达式深入与流初步
Lambda表达式深入: 在上一次[http://www.cnblogs.com/webor2006/p/8135873.html]中介绍Lambda表达式的作用时,其中说到这点: 如标红处所说,既然 ...
- 【PKUSC2018】星际穿越
被 scb 神仙教育来扫荡北大营题目 Orz Description https://loj.ac/problem/6435 Solution 首先有个很显然的性质,就是对于一组询问 \(l,r,x\ ...