HDU 4372 Count The buildings
Recommend this small brother's, I think people say the ash often good.
Note The data range, n,f,b are in (0,2000] range, and the first Stirling number array range is s[2000+5][2000+5] (if you open 4000 memory overrun), so to add a pair (f+b-2) judgment, otherwise C + + can not be, g++ is able to. Hands-on practice, although I do not know why g++ so robust ...
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <cmath>6 using namespacestd;7typedefLong Longll;8 Constll MOD =1000000007;9 Const intMAXN =2005;Ten ll S[MAXN][MAXN]; One ll C[MAXN][MAXN]; A - voidGet_combination_number () - { the for(inti =1; I <= -; i++) - { -c[i][0] = C[i][i] =1; - for(intj =1; J < I; J + +) +C[I][J] = (c[i-1][j-1]+c[i-1][J])%MOD; - } + } A at voidGet_stirling_number_i () - { -s[0][0] =1; - for(inti =1; I <= -; i++) - { -s[i][0] =0; inS[i][i] =1; - for(intj =1; J < I; J + +) to { +S[I][J] = (s[i-1][j-1] + (I-1) *s[i-1][J])%MOD; - } the } * } $ Panax Notoginseng intMain () - { the Get_combination_number (); + Get_stirling_number_i (); A intT; thescanf"%d", &T); + while(t--) - { $ intN, F, b; $scanf"%d%d%d", &n, &f, &b); -ll ans =0; - if(f+b-2<= N-1) theAns = (s[n-1][f+b-2] * c[f+b-2][f-1]) %MOD; - ElseWuyiAns =0; theprintf"%lld\n", ans); - } Wu return 0; -}
HDU 4372
"Stirling number I"