hdu 1023 Train Problem II

Train Problem II

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 9930    Accepted Submission(s): 5317


Problem Description
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.
 

 

Input
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.
 

 

Output
For each test case, you should output how many ways that all the trains can get out of the railway.
 

 

Sample Input
1 2 3 10
 

 

Sample Output
1 2 5 16796
Hint
The result will be very large, so you may not process it by 32-bit integers.
 
 
 
题解:大整数的加法     每一次都一步一步累加上去的话   应该也是可以得    
但是题目不知道要询问多少次   并且n最大也就是100
所以可以先使用大整数加法打表
然后只要输出对应的字符串就可以了
 1 #include<iostream>
 2 #include<string.h>
 3 using namespace std;
 4 char a[111][111][111];
 5 void add(char a[],char b[],char c[])
 6 {
 7     char t[111],e[111];
 8     int i=strlen(b)-1,j=strlen(c)-1,k=0;
 9     while(i>=0&&j>=0)
10     {
11         t[k]=b[i]+c[j]-'0';
12         k++;
13         i--;
14         j--;
15     }
16     while(i>=0)
17     {
18         t[k]=b[i];
19         k++;
20         i--;
21     }
22     while(j>=0)
23     {
24         t[k]=c[j];
25         k++;
26         j--;
27     }
28     t[k]='0';
29     for(i=0;i<k;i++)
30     if(t[i]>'9')
31     {
32         t[i]=t[i]-10;
33         t[i+1]++;
34         e[i]=t[i];
35     }
36     else
37     e[i]=t[i];
38     if(t[k]=='0')
39     e[k]='\0';
40     else
41     {
42         e[k]=t[k];
43         e[k+1]='\0';
44     }
45     for(i=strlen(e)-1,j=0;i>=0;i--,j++)
46     a[j]=e[i];
47     a[j]='\0';
48 }
49 int main()
50 {
51     int i,j,m,n,k,t;
52     a[0][0][0]='0';
53     a[0][0][1]='\0';
54     for(i=1;i<=100;i++)
55     {
56         a[0][i][0]='1';
57         a[0][0][1]='\0';
58     }
59     for(i=1;i<=100;i++)
60     for(j=0;j+i<=100;j++)
61     if(j>0)
62     add(a[i][j],a[i-1][j+1],a[i][j-1]);
63     else
64     add(a[i][j],a[i-1][j+1],"0");
65     while(cin>>n)
66     cout<<a[n][0]<<endl;
67 }
View Code

 

posted @ 2017-09-06 09:08  红雨520  阅读(116)  评论(0编辑  收藏  举报