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的更多相关文章

  1. 【HDU 4372】 Count the Buildings (第一类斯特林数)

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  2. [Hdu4372] Count the Buildings

    [Hdu4372] Count the Buildings Description There are N buildings standing in a straight line in the C ...

  3. HDU4372 Count the Buildings —— 组合数 + 第一类斯特林数

    题目链接:https://vjudge.net/problem/HDU-4372 Count the Buildings Time Limit: 2000/1000 MS (Java/Others)  ...

  4. HDU 4372 Count the Buildings

    Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Othe ...

  5. HDU4372 Count the Buildings (+题解:斯特林数)

    题面 (笔者翻译) There are N buildings standing in a straight line in the City, numbered from 1 to N. The h ...

  6. HDU 4372 Count the Buildings:第一类Stirling数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4372 题意: 有n栋高楼横着排成一排,各自的高度为1到n的一个排列. 从左边看可以看到f栋楼,从右边看 ...

  7. HDU 4372 Count the Buildings [第一类斯特林数]

    有n(<=2000)栋楼排成一排,高度恰好是1至n且两两不同.现在从左侧看能看到f栋,从右边看能看到b栋,问有多少种可能方案. T组数据, (T<=100000) 自己只想出了用DP搞 发 ...

  8. HDU 4372 Count the Buildings——第一类斯特林数

    题目大意:n幢楼,从左边能看见f幢楼,右边能看见b幢楼 楼高是1~n的排列. 问楼的可能情况 把握看到楼的本质! 最高的一定能看见! 计数问题要向组合数学或者dp靠拢.但是这个题询问又很多,难以dp ...

  9. 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),肯定搞不定 然后想了好久没有效果,就去逛大神博客了,结果发现需要用到 ...

随机推荐

  1. node 环境安装

    记录一下, 方便自己需要时用, 免得到处找 1. 官网下载安装node(选择LTS长期支持版本), 一路点击next即可(傻瓜式安装) 2. 验证是否正确安装, 打开命令窗口, 执行 node -v ...

  2. Sql Server--如何自动备份数据

    下面我来讲一下如何通过维护计划来实现完整备份+差异备份: (1)在SSMS的对象资源管理器中右击“维护计划”,选择“维护计划向导”,系统将弹出向导窗口,如图: 这里向导已经告诉我们维护计划到底能够干什 ...

  3. c#操作word书签

    因项目需要,给word文档的书签赋值,框架没有相关内容,于是自己上网加上查看文档,成功搞定该功能.下面是我的实现过程: 首先需要引用nuget包: Microsoft.Office.Interop.W ...

  4. 题解 P2859 【[USACO06FEB]摊位预订Stall Reservations】

    题目链接: https://www.luogu.org/problemnew/show/P2859 思路: 首先大家会想到这是典型的贪心,类似区间覆盖问题的思路,我们要将每段时间的左端点从小到大排序, ...

  5. kbmMW 5.09测试报告(1)-Scheduler

    这个版本除了增加新的SmartBinding功能,同时提供了大量的功能更新以及bug修正.其中,SmartBinding的介绍,xalion已经第一时间写了初识kbmmw 中的smartbind功能, ...

  6. makefile学习之函数

    GNU make支持内置函数以及用户自定义函数,下面结合例子简单介绍一下. gnu make版本: 4.1 一.用户自定义函数 格式: $(call macro-name{, param1 ···}) ...

  7. 记录旧手机(米6)安装Linux(Ubuntu16.04)踩过的坑

    旧的小米6在抽屉吃灰半年,一直没想好要怎么处理,于是就想着安装Linux. 完整教程来自https://blog.csdn.net/Greepex/article/details/85333027 原 ...

  8. Centos网卡名称命名

    1. vim /etc/sysconfig/grub     编辑/etc/sysconfig/grub文件 添加  net.ifnames=0 biosname=0 GRUB_TIMEOUT= GR ...

  9. SQL 语句 连接

    SQL连接可以分为内连接.外连接.交叉连接. 数据库数据:             book表                                          stu表 1.内连接 ...

  10. 1.1.EJB概述

    1.EJB概述: Enterprice JavaBeans是一个用于分布式业务应用的标准服务端组件模型.采用Enterprice JavaBeans架构编写的应用是可伸的.事务性的. 多用户安全的.采 ...