HDU 4372 - Count the Buildings(组合计数)  第一类斯特拉数

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=2e3+10;
const int mod=1e9+7;
ll s[maxn][maxn];
int A[maxn];
int B[maxn];
int quick(int x,int n){
    int ans=1;
    while(n){
        if(n&1) ans=1ll*ans*x%mod;
        x=1ll*x*x%mod;
        n=n/2;
    } return ans;
}
void make(){
    int n=maxn-1;
    A[0]=1; B[0]=1;
    for(int i=1;i<=n;i++) A[i]=1ll*A[i-1]*i%mod;
    B[n]=quick(A[n],mod-2); //cout<<B[n]<<endl;
    for(int i=n-1;i>=1;i--) B[i]=1ll*B[i+1]*(i+1)%mod;
}
int CC(int n,int c){
    if(c>n) return 0;
    return 1ll*A[n]*B[n-c]%mod*B[c]%mod;
}
void make_stl(){
    int n=maxn-1;
     for(int i=1;i<=n;i++){
        s[i][0] =0;
         s[i][i] =1;
        for(int j=1;j<i;j++)
             s[i][j] = (s[i-1][j-1]+(s[i-1][j]*(i-1))%mod)%mod;
     }
}
int main(){  make(); make_stl();
    int T; scanf("%d",&T);
    while(T--){
        int n,f,b; scanf("%d %d %d",&n,&f,&b);
        if(f+b-1>2000){
            printf("0\n"); continue;
        }
        ll ans=1ll*s[n-1][f+b-2]*CC(f+b-1-1,f-1);
        printf("%lld\n",ans%mod);
    }
}