Problem Statement:
Hdoj Problem-1023
Problem Resolution:
Application of Cattleya number (Catalan)
Basic properties:
F (n) = f (1) f (n-1) + F (2) f (n-2) + ... + f (n-2) f (2) + F (n-1) f (1);
F (n) = c (2n, N)/(n+1) = C (2n-2, n-1)/n;
Cn = (4n-2)/(n+1) Cn-1
Code Explanation:
1#include <iostream>2#include <cstdio>3#include <memory.h>4 5 using namespacestd;6 7 #defineMAX 1018 #defineBASE 100009 Ten voidMultiplyintA[],intLenintb) { One for(inti=len-1, carry=0; i>=0; i--) { Acarry + = b *A[i]; -A[i] = carry%BASE; -Carry/=BASE; the } - } - - voidDivideintA[],intLenintb) { + for(intI=0, div=0; i<len; i++) { -div = div * BASE +A[i]; +A[i] = div/b; ADiv%=b; at } - } - - intMain () - { - intI, J, h[101][max]; inmemset (h[1],0, max*sizeof(int)); - for(i=2, h[1][max-1]=1; i<= -; i++) { tomemcpy (H[i], h[i-1], max*sizeof(int)); +Multiply (H[i], MAX,4*i-2); -Divide (H[i], MAX, i+1); the } * $ while(Cin >> I && i>=1&& I <= -) {Panax Notoginseng for(j=0; J<max && h[i][j]==0; J + +); -printf"%d", h[i][j++]); the for(; j<max; J + +) +printf"%04d", H[i][j]); Acout <<Endl; the } + return 0; -}
Resources:
Wikipedia
CSDN
Reprint Please specify source: http://www.cnblogs.com/michaelwong/p/4346692.html
Train problem II