uva 12034
1 /* 比赛的名次的所有方案数 _________________________________________________________________________________ 2 3 #include <iostream> 4 #include <map> 5 #include <cmath> 6 #include <vector> 7 #include <cstdio> 8 #include <string> 9 #include <cstring> 10 #include <algorithm> 11 using namespace std; 12 #define fir first 13 #define sec second 14 #define pb(x) push_back(x) 15 #define mem(A, X) memset(A, X, sizeof A) 16 #define REP(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) 17 #define rep(i,l,u) for(int (i)=(int)(l);(i)>=(int)(u);--(i)) 18 #define foreach(e,x) for(__typeof(x.begin()) e=x.begin();e!=x.end();++e) 19 typedef long long LL; 20 typedef unsigned long long ull; 21 typedef pair<long,long> pll; 22 23 24 LL T,n; 25 const LL mod=10056; 26 LL f[1000+10]; 27 28 29 LL c[1005][1005]; 30 const int maxn=1001; 31 const int MOD=10056; 32 void init() { 33 for(int i = 0; i <= maxn; i++) { 34 c[i][0] = c[i][i] = 1; 35 for(int j = 1; j < i; j++) 36 c[i][j] = (c[i-1][j] + c[i-1][j-1]) % MOD; 37 } 38 } 39 40 int main() 41 { 42 freopen("in.txt","r",stdin); 43 44 init(); 45 mem(f,0); f[0]=1; 46 REP(n,1,1000) 47 REP(i,1,n) f[n]+=c[n][i]*f[n-i]%mod; 48 while(cin>>T) 49 { 50 REP(kase,1,T) 51 { 52 int n; 53 cin>>n; 54 cout<<"Case "<<kase<<": "<<f[n]%mod<<endl; 55 } 56 57 } 58 return 0; 59 } 60 61 /* 62 note : 运用子问题寻找递推关系。 63 debug : 组合数初始化的时候,牵扯到取模的时候不能用横向的递推关系,会导致出现0, 64 optimize: 65 */ 66