HDU 1023 Train Problem II 高精度卡特兰数
High-precision Catalan number
This is a classic problem of finding the number of stack push ans pop sequences. The only headache is that it requires high precision.
How to determine whether it is a Catalan number
For a more detailed introduction to the Catalan number,see oi-wiki and wikipedia
I think there is another simple way to judge, which is to see whether the first few numbers are consistent with the Catalan number. If they are the same, then it is likely to be a correct guess.
Algortithm Implementation
We use catalan[i][j]
to represent the j-th digital of the i-th Catalan number.
The formula I use is h(n) = (4n-2)*h(n-1)/(n+1)
.
Code
1 |
|
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.
Comments