`
hulunberbus
  • 浏览: 858852 次
文章分类
社区版块
存档分类
最新评论

hdu 1023 Train Problem II catalan数列 大数乘除

 
阅读更多

Train Problem II

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


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

很久写博客了。 今天下午都没课。刷了下hdu。

这道题是一道catalan数列的题。之前做的是hdu 1022train problem I 。 那题简单的模拟入栈和出栈。

刚做这道题时,我用递归的思维,只推出f[n]=f[1]*f[n-1]+f[2]*f[n-2]+···f[n-1]*f[1] 然后 用循环打表。但没考虑大数。WA了。 从网上查了catalan 数的资料。才查出catalan数的递归的另一个表达式

f[n]=f[n-1]*(4*n-2)/(n+1),貌似这个表达式是根据关系式 f[n]=f[1]*f[n-1]+f[2]*f[n-2]+···f[n-1]*f[1], 用数学方法推出的,我没看懂。 网上可以查到。同时有个收获 :ACM中 catalan 数列相关的问题很多,日后继续学习。

catalan数相关链接 http://baike.baidu.com/view/1396146.htm

http://www.cppblog.com/MiYu/archive/2010/08/07/122573.html

还有就是用到了大数的乘除 。

下面是代码和思路


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics