hdu 4372 Count the Buildings
推荐这位小哥的,我觉得人家说的灰常的好。
注意数据范围,n,f,b均在(0,2000]范围内,而第一斯特林数的数组范围却是s[2000+5][2000+5]的(你要是开4000会内存超限),所以要加一个对(f+b-2)的判断,否则C++过不了,G++是能过的。亲身实践,虽然不知道G++为什么这么鲁棒...
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<iostream> 2 #include<cstdio> 3 #include<cstdlib> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 typedef long long ll; 8 const ll MOD = 1000000007; 9 const int maxn = 2005; 10 ll s[maxn][maxn]; 11 ll C[maxn][maxn]; 12 13 void get_Combination_Number() 14 { 15 for(int i = 1; i <= 2000; i++) 16 { 17 C[i][0] = C[i][i] = 1; 18 for(int j = 1; j < i; j++) 19 C[i][j] = (C[i-1][j-1]+C[i-1][j])%MOD; 20 } 21 } 22 23 void get_Stirling_Number_I() 24 { 25 s[0][0] = 1; 26 for(int i = 1; i <= 2000; i++) 27 { 28 s[i][0] = 0; 29 s[i][i] = 1; 30 for(int j = 1; j < i; j++) 31 { 32 s[i][j] = (s[i-1][j-1] + (i-1)*s[i-1][j]) % MOD; 33 } 34 } 35 } 36 37 int main() 38 { 39 get_Combination_Number(); 40 get_Stirling_Number_I(); 41 int T; 42 scanf("%d", &T); 43 while(T--) 44 { 45 int n, f, b; 46 scanf("%d%d%d", &n, &f, &b); 47 ll ans = 0; 48 if(f+b-2 <= n-1) 49 ans = (s[n-1][f+b-2] * C[f+b-2][f-1]) % MOD; 50 else 51 ans = 0; 52 printf("%lld\n", ans); 53 } 54 return 0; 55 }