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),肯定搞不定 然后想了好久没有效果,就去逛大神博客了,结果发现需要用到 ...
随机推荐
- 转SSL/TLS协议
TLS名为传输层安全协议(Transport Layer Protocol),这个协议是一套加密的通信协议.它的前身是SSL协议(安全套接层协议,Secure Sockets Layer).这两个协议 ...
- DVWA reCAPTCHA key: Missing
修改dvwa文件夹下文件config.inc.php change: $_DVWA[ 'recaptcha_public_key' ] = ' '; $_DVWA[ 'recaptcha_privat ...
- 01docker基本概念
docker基本概念 官方文档URL:https://docs.docker.com/ 1.Docker的构想是要实现"Build, Ship and Run Any App, Anywhe ...
- 进阶Java编程(8)反射应用案例
1,反射实例化对象 经过一系列分析之后可以发现虽然获得了Class类的实例化对象但是依然觉得这个对象获取的意义不是很大,所以为了进一步的帮助大家理解反射的核心意义所在,下面将通过几个案例进行说明(都是 ...
- Java lesson19homework
package com.xt.lesson19; /** * 已知如下: 下表为某班级四次考试成绩单, 1. 要求使用HashMap<String, Integer>存储每次考试的成绩(k ...
- 【原创】大数据基础之Chronos
官方:https://mesos.github.io/chronos/ mesos集群中替换crontab Chronos A fault tolerant job scheduler for Mes ...
- shiro学习(五、springboot+shiro+mybatis+thymeleaf)
入门shiro(感觉成功了)首先感谢狂神,然后我就一本正经的复制代码了 项目结构 运行效果 数据库 <dependencies> <!-- thymeleaf-shiro整合包 -- ...
- 学习javascript,您将发现以下两个学习指南
学习javascript,您将发现以下两个学习指南,一个是初学者的,另一个是茄子一号经验丰富的程序员和Web开发人员的.你想学习javascript并对它有兴趣.我想这就是你来这里的原因,你做了一个明 ...
- git 多账户添加ssh秘钥
生成秘钥的步骤: ssh-keygen -t rsa -C "xxxx@qq.com" 添加秘钥 在不同的域中添加相同的秘钥是没有问题的,比如 github.com / code. ...
- 2.Struts2-Action
struts.xml文件中 action 标签中几个属性的作用 1.name:为action命名,输入url访问时,需要带上action的name,通过name知道访问哪个action(通过class ...