题目:http://acm.hdu.edu.cn/showproblem.php?pid=4372

首先,最高的会被看见;

然后考虑剩下 \( x+y-2 \) 个被看见的,每个带了一群被它挡住的楼,其实方案数是圆排列,每个圆从最高的楼开始断掉都是不同的方案;

再把这 \( x+y-2 \) 个圆排列分成两组放左右两边,它们按最高楼的高度就自动有顺序了,不必再算;

\( s[i][j] \) 表示第一类斯特林数,答案就是 \( s[n-1][x+y-2] * C_{x+y-2}^{x-1} \)

注意题目不保证有解,所以如果不判一下的话就把数组开成 4000 防爆。

代码如下:

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
int const xn=,mod=1e9+;
int s[xn][xn],c[xn][xn];
int rd()
{
int ret=,f=; char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=; ch=getchar();}
while(ch>=''&&ch<='')ret=ret*+ch-'',ch=getchar();
return f?ret:-ret;
}
int upt(int x){while(x>=mod)x-=mod; while(x<)x+=mod; return x;}
void init()
{
int mx=;
s[][]=;
for(int i=;i<=mx;i++)
for(int j=;j<=i;j++)
s[i][j]=(s[i-][j-]+(ll)s[i-][j]*(i-))%mod;
for(int i=;i<=mx;i++)c[i][]=;
for(int i=;i<=mx;i++)
for(int j=;j<=i;j++)
c[i][j]=upt(c[i-][j]+c[i-][j-]);
}
int main()
{
init(); int T=rd();
while(T--)
{
int n=rd(),x=rd(),y=rd();
if(x+y->n)puts("");//!
else printf("%lld\n",(ll)s[n-][x+y-]*c[x+y-][x-]%mod);
}
return ;
}

hdu 4372 Count the Buildings —— 思路+第一类斯特林数的更多相关文章

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

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

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

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

  3. 【HDU4372】Count the Buildings (第一类斯特林数)

    Description $N$座高楼,高度均不同且为$1~N$中的数,从前向后看能看到$F$个,从后向前看能看到$B$个,问有多少种可能的排列数. $T$组询问,答案模$1000000007$.其中$ ...

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

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

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

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

  6. HDU 4372 Count the Buildings

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

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

  8. hdu 4372 Count the Buildings 轮换斯特林数

    题目大意 n栋楼有n个不同的高度 现在限制从前面看有F个点,后面看有B个点 分析 最高那栋楼哪都可以看到 剩下的可以最高那栋楼前面分出F-1个组 后面分出B-1个组 每个组的权值定义为组内最高楼的高度 ...

  9. HDU 4372 Count the Buildings 组合数学

    题意:有n个点上可能有楼房,从前面可以看到x栋楼,从后面可以看到y栋,问楼的位置有多少种可能. 印象中好像做过这个题,

随机推荐

  1. spider_action

    spider from mobile to mobile to mobile from selenium import webdriver from selenium.webdriver.chrome ...

  2. 【模式识别】CART和GML AdaBoost MATLAB TOOLBOX

    GML AdaBoost Matlab Toolbox是一款很优秀的AdaBoost工具箱,内部实现了Real AdaBoost, Gentle AdaBoost和Modest AdaBoost三种方 ...

  3. windows10 Python2和Python3共存

    通过配置环境变量,达到使用python命令启动python2,使用python3命令启动python3,pip启动pip2, pip3启动pip3的目的,互不影响. 1.安装python2.7  安装 ...

  4. vim中使用sed去除网上copy的源代码行号和空格

    有些时候,在网上搜索到的代码都包含有行号,高亮显示控件不支持直接提取,如: test.sh 01 #!/bin/bash 02 echo “aaa” 简单的去掉行号和前面的空格: 方案一: 1.vim ...

  5. t-sql判断数据库对象是否存在

    1 系统表sys.sysobjects 在数据库中创建的每个对象(例如约束.默认值.日志.规则以及存储过程)都对应一行,详细介绍参考MSDN 2 OBJECTPROPERTY 返回当前数据库中架构范围 ...

  6. 3django url name详解

    打开urls.py from django.conf.urls import url from django.contrib import admin from calc import views a ...

  7. ubuntu android studio 编译及运行错误Error retrieving parent for item: No resource found that matches the given name

    安装好android studio并且安装其它需要的SDK或组件后,根据向导生成新的项目, 编译或运行时可能会出现下面的错误: Error:Error retrieving parent for it ...

  8. 暑假集训第一周比赛G题

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=83146#problem/G G - 向 Crawling in process... C ...

  9. how to close the old Session - if the same username starts a new Session?

    Question: want to close the old Session - if the same username starts a new Session Any ideas how i ...

  10. 51nod 1525 && CF566D

    题意:给定n个元素,现在有2种合并操作和1种询问操作 1.单独合并两个元素所在的集合 2.合并一个区间内的元素所在的集合 询问:两个元素是否属于统一集合 神犇题解 感觉又涨了新姿势啊..我们最恼火的是 ...