[Question ]:
There are 2 * n consecutive numbers on a ring. Calculate the number of methods that concatenate these two numbers and their connected edges do not intersect.
[Knowledge point ]:
Mathematics + Catalan count
H (1) = 1, h (0) = 1
Recursion 1: H (n) = H (0) * H (n-1) + H (1) * H (n-2) +... + H (n-1) H (0) (N> = 2)
Recursion 2: H (n) = (4 * N-2)/(n + 1) * H (n-1 );
The recursive relationship is interpreted as H (n) = C (2n, N)/(n + 1) (n = 1, 2, 3 ,...)
[Question ]:
For typical applications of Catalan, the answer to 2 * n is H (n ).
[Code ]:
1 import java.io.*; 2 import java.util.*; 3 import java.math.*; 4 5 public class Main { 6 public static void main(String args[]){ 7 Scanner cin = new Scanner( 8 new BufferedInputStream(System.in)); 9 BigInteger[] B = new BigInteger[120];10 B[0] = new BigInteger("1");11 B[1] = new BigInteger("1");12 for(int i = 2; i <= 100; i++){13 B[i] = B[i - 1].multiply(14 BigInteger.valueOf(4 * i - 2)).divide(15 BigInteger.valueOf(i + 1));16 }17 while(true){18 int n = cin.nextInt();19 if(n == -1)20 break;21 System.out.println(B[n]);22 }23 }24 }