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;
}