Count the Buildings
K - Count the Buildings
参考:Count the Buildings
思路可以借鉴,但是代码略有问题
写的时候 re 了 9 发,然后把变量定义的顺序换了一下居然 A 了,以为这个是个骚操作,最后才发现是真的会越界,当 f+b>n+2 的时候就有可能会发生越界,而这种情况,if 判断一下就好
代码:
// Created by CAD on 2019/8/17.
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const int mod=1000000007;
const int maxn=2010;
ll c[maxn][maxn],s[maxn][maxn];
int main()
{
memset(s, 0, sizeof(s));
memset(c, 0, sizeof(c));
s[0][0]=1;
for (int i=0; i<=maxn-10; ++i) c[i][0]=1;
for (int i=1; i<=maxn-10; ++i)
for (int j=1; j<=maxn-10; ++j){
s[i][j]=(s[i-1][j-1]+(i-1)*s[i-1][j])%mod;
c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
}
int t; scanf("%d", &t);
while (t--){
int n,f,b;
scanf("%d%d%d",&n,&f,&b);
if(f+b>n+2) cout<<0<<endl;
else printf("%lld\n",(s[n-1][f+b-2]*c[f+b-2][f-1])%mod);
}
return 0;
}