Count the Buildings
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2551 Accepted Submission(s): 827
Problem Description
There are N buildings standing in a straight line in the City, numbered from 1 to N. The heights of all the buildings are distinct and between 1 and N. You can see F buildings when you standing in front of the first building and looking forward, and B buildings when you are behind the last building and looking backward. A building can be seen if the building is higher than any building between you and it.
Now, given N, F, B, your task is to figure out how many ways all the buildings can be.
Now, given N, F, B, your task is to figure out how many ways all the buildings can be.
Input
First line of the input is a single integer T (T<=100000), indicating there are T test cases followed.
Next T lines, each line consists of three integer N, F, B, (0<N, F, B<=2000) described above.
Next T lines, each line consists of three integer N, F, B, (0<N, F, B<=2000) described above.
Output
For each case, you should output the number of ways mod 1000000007(1e9+7).
Sample Input
23 2 23 2 1
Sample Output
21
刚学了斯特林数
这题没想到...
大致可以如下思考
前后两个视线一定是被最高那个的挡住
那之后又怎么做呢
考虑 前面有 F-1 个高度单调递增 后面有 B-1 个
发现这 F+B-2 个可以把它们后面跟着的合起来 变成一段
这样就是 F+B-2 段
这样就可以从思维上映射到第一类斯特林数
// s(n,m) 表示用 n 个元素 构成 m 个循环排列的方案数
n-1 个元素 构成 F+B-2 段 每段取其最高者为首
这 F+B-2 段即可以看成 F+B-2 个循环排列
之后就是前后之分 乘上个组合数即可
#include<cmath>
#include<ctime>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<iomanip>
#include<vector>
#include<string>
#include<bitset>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
inline int read()
{
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){x=10*x+ch-'0';ch=getchar();}
return x*f;
}
void print(int x)
{if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}
const int N=2010,mod=int(1e9)+7;
int c[N][N],s[N][N];
void initial()
{
register int i,j;
c[0][0]=s[0][0]=1;
for(i=1;i<N;++i)
{
c[i][0]=1;
for(j=1;j<=i;++j)
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod,
s[i][j]=(1ll*(i-1)*s[i-1][j]+s[i-1][j-1])%mod;
}
}
int main()
{
initial();
int T=read(),n,f,b;
while(T--)
{
n=read();f=read();b=read();
if(f+b>n+1) puts("0");
else print(1ll*s[n-1][f+b-2]*c[f+b-2][f-1]%mod),puts("");
}
return 0;
}