1 /*
2 Problem Description
3 As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway.
4
5
6
7 Input
8 The input contains several test cases. Each test cases consists of a number N(1<=N<=100). The input is terminated by the end of file.
9
10
11
12 Output
13 For each test case, you should output how many ways that all the trains can get out of the railway.
14
15
16
17 Sample Input
18 1
19 2
20 3
21 10
22
23
24 Sample Output
25 1
26 2
27 5
28 16796
29
30 HintHint
31 The result will be very large, so you may not process it by 32-bit integers.
32
33
34 Author
35 Ignatius.L
36
37 */
38 /*Description: to
39 *
40 * Author: Vincent
41 *
42 * Date:2010/04/
43 * Contact:agilely@126.com
44 * Zju CS Lab
45 */
46 //按1、2、3,,,来的车,给出车数,求最大出站种数
47 #include <stdio.h>//查表。。结果事先算完放入sum[]
48 #include <string.h>
49 char temp[1100]={0},sum[1100]={0};
50 int main()
51 {
52 void multipe(char a[],char b[]);
53 void puls(char a[],char b[]);//函数声明
54 char result[110][1000] = {0};
55 char tt[1100],hh[1100];
56 int i,j,k;
57 int n;
58 result[0][0] = 49;//49为ASCII的1
59 result[1][0] = 49;
60 for( i=2; i <= 101; i ++)
61 {
62 result[i][0]='0';
63 for(j = 0;j < i;j ++)
64 {
65 memset(tt,0,sizeof(tt));
66 memset(hh,0,sizeof(hh));
67 strcpy(tt,result[j]);
68 strcpy(hh,result[i-j-1]);
69 multipe(tt,hh);
70 puls(temp,result[i]);
71 memset(result[i],0,sizeof(result[i]));
72 for(k=0;sum[k];k++)
73 result[i][k]=sum[k];
74 }
75 }
76 while(scanf("%d",&n)!=EOF && n != -1)
77 printf("%s\n",result[n]);
78 return 0;
79 }
80 void multipe(char a[],char b[])
81 {
82 int la,lb;
83 char t[1000];
84 int c[2000];
85 int i,j,l;
86 la=strlen(a);
87 lb=strlen(b);
88 memset(t,0,sizeof(t));
89 strcpy(t,a);
90 for(j=0,i=la-1;i>=0;i--) a[j++]=t[i];
91 memset(t,0,sizeof(t));
92 strcpy(t,b);
93 for(j=0,i=lb-1;i>=0;i--) b[j++]=t[i];
94 memset(c,0,sizeof(c));
95 for(i=0;i<la;i++)
96 for(j=0;j<lb;j++)
97 {
98 c[i+j]+=(a[i]-48)*(b[j]-48);
99 c[i+j+1]+=c[i+j]/10;
100 c[i+j]%=10;
101 }
102 l=la+lb+1;
103 while(l>=0&&!c[l]) l--;
104 if(l<0) c[0]=0;
105 memset(temp,0,sizeof(temp));
106 if(l<0) temp[0]='0';
107 for(i=l,j=0;i>=0;i--,j++)
108 temp[j]=c[i]+48;
109 }
110 void puls(char a[],char b[])
111 {
112 int i,j,k1,la,lb,s,lsum;
113 int c=0;
114 char h;
115 for(j=0;a[j];j++); la=j-1;
116 for(j=0;b[j];j++); lb=j-1;
117 memset(sum,0,sizeof(sum));
118 k1=0;
119 while(1){
120 if(la<0&&lb<0) break;
121 else if(la<0) s=b[lb--]-48;
122 else if(lb<0) s=a[la--]-48;
123 else s=a[la--]-48+b[lb--]-48;
124
125 if(k1==0) {sum[k1]=s%10+48 ;c=s/10;}
126 else {sum[k1]=(s+c)%10+48;c=(s+c)/10;}
127 k1++;
128 }
129 if(c!=0) sum[k1]=c+48;
130 lsum=strlen(sum)-1;
131 for(i=0;i<=lsum/2;i++)
132 {h=sum[i];sum[i]=sum[lsum-i];sum[lsum-i]=h;}
133 }
134
135