题意分析
首先,高度为 $n$ 的建筑是不会被挡住的。
剩下的建筑即 $n-1$ 个。将这 $n-1$ 个建筑划分为 $A+B-2$ 个圆排列即可,每个排列内最高的建筑为起始端。
只需要考虑在 $n$ 的左侧还是右侧,因此乘上一个组合数。
故,答案为:
\[\begin{bmatrix}n-1\\A+B-2\end{bmatrix}\dbinom{A+B-2}{A-1}\]AC 代码
时间复杂度:$\mathcal O(nk+T)$。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//#include<bits/stdc++.h>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<iomanip>
#include<cstdio>
#include<string>
#include<vector>
#include<cmath>
#include<ctime>
#include<deque>
#include<queue>
#include<stack>
#include<list>
using namespace std;
#define int long long
constexpr const int N=50000,V=100,P=1e9+7;
int fact[N+1],factInv[N+1];
int qpow(int base,int n){
int ans=1;
while(n){
if(n&1){
ans=1ll*ans*base%P;
}
base=1ll*base*base%P;
n>>=1;
}
return ans;
}
void pre(){
fact[0]=1;
for(int i=1;i<=N;i++){
fact[i]=1ll*i*fact[i-1]%P;
}
factInv[N]=qpow(fact[N],P-2);
for(int i=N-1;i>=0;i--){
factInv[i]=1ll*(i+1)*factInv[i+1]%P;
}
}
int C(int n,int m){
if(n<0||m<0||n<m){
return 0;
}
return 1ll*fact[n]*factInv[m]%P*factInv[n-m]%P;
}
int brack(int n,int m){
if(n<0||m<0||n<m){
return 0;
}
if(!m){
return !n;
}
static int mem[N+1][V+V+1];
if(mem[n][m]){
return mem[n][m];
}
return mem[n][m]=(1ll*brack(n-1,m-1)+(n-1ll)*brack(n-1,m)%P)%P;
}
int f(int n,int A,int B){
return (1ll*C(A+B-2,A-1)*brack(n-1,A+B-2))%P;
}
main(){
/*freopen("test.in","r",stdin);
freopen("test.out","w",stdout);*/
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
pre();
int T;
cin>>T;
while(T--){
int n,A,B;
cin>>n>>A>>B;
cout<<f(n,A,B)<<'\n';
}
cout.flush();
/*fclose(stdin);
fclose(stdout);*/
return 0;
}