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.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.Output For each case, you should output the number of ways mod
1000000007(1e9+7).
先考虑从一边看的情况,如果
n
栋楼看到了
从两边看也一样,按照最高点分成左右两部分,答案是
#include<cstdio>
#include<algorithm>
using namespace std;
#define LL long long
const int mod=1000000007,maxn=2000;
int c[maxn+10][maxn+10],s[maxn+10][maxn+10];
int main()
{
int T,n,f,b;
for (int i=0;i<=maxn;i++) c[i][0]=1;
s[0][0]=1;
for (int i=1;i<=maxn;i++)
for (int j=1;j<=i;j++)
{
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
s[i][j]=(s[i-1][j-1]+(LL)(i-1)*s[i-1][j])%mod;
}
scanf("%d",&T);
while (T--)
{
scanf("%d%d%d",&n,&f,&b);
if (f+b-1>n) printf("0\n");
else printf("%d\n",(LL)c[f+b-2][f-1]*s[n-1][f+b-2]%mod);
}
}