码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1023 Train Problem II

时间:2015-12-02 14:21:57      阅读:121      评论:0      收藏:0      [点我收藏+]

标签:

Train Problem II

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


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.
 
 
 
 
 
 
 
 

#include<stdio.h>
#include<string.h>
int a[105][105];
void C()
{
int i,j,k,m,l;
a[1][0]=1;
a[1][1]=1;
a[2][0]=1;
a[2][1]=2;
l=1;
for(j=3;j<=100;j++)
{
k=0;
for(i=1;i<=l;i++)
{
m=a[j-1][i]*(4*j-2)+k;
a[j][i]=m%10;
k=m/10;
}
while(k)
{
a[j][++l]=k%10;
k=k/10;
}
for(i=l;i>=1;i--)
{
m=a[j][i]+k*10;
a[j][i]=m/(j+1);
k=m%(j+1);
}
while(!a[j][l])
l--;
a[j][0]=l;
}
}
int main()
{
C();
int n;
while(scanf("%d",&n)!=EOF)
{
int i;
for(i=a[n][0];i>=1;i--)
printf("%d",a[n][i]);
printf("\n");
}
return 0;
}

HDU 1023 Train Problem II

标签:

原文地址:http://www.cnblogs.com/-lgh/p/5012631.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!