Javaの大きい整数はcatalan数を計算することを実現します.


Problem:
http://acm.sgu.ru/problem.php?contest=0&problem=130
Circule
On a circele border there re 2 k different points A 1,A 2,…,A 2 k,located contigously.The points connect k chorrds so that each of points A 1,A 2,…A 2 k is the end point of one chord.Chords divide the circele into parts.You have to find N-the number of different ways to connect the points the circus the is brooken into minimal possible amount of parts.P.
Input     k
Output  two numbers N and P delimited by space.
Sample Input
2
Sample Output
2 3

//
Sgu  130. Circule  
(
catalan number

import
 java.util.

; 
public
 
クラス
 Solution 

{            public static long  catalan(int n)  // MAX n=33      ...{         if(n=0)    return 1;         else return (4*n−2)*catalan(n−1)/(n+1);     }      public static void main(String) args[] ローソン Exception         ...{             Scanner cin=new Scanner(System.in)             要点 k= cin.nextInt();             long s=catalan(k);             System.out.println(s+" "+(k+1)                           return;         }     }

     
//
 f(n)= C(2 n,n)/(n+1)  Big Integer

     
public
 
static
 Big Integer cat
要点
 n) 

         if (n==1 || n==0)             return Big Integer.ONE;         Big Integer cat=new Big Integer(Integer.toString(2*n))、         Big Integer twice=new Big Integer(Integer.toString(2*n))、         Big Integer i =new Big Integer(「1」)、         for (int j=1; j             cat=cat.multiplly(twice.subtract(i);         i=i.add(BigInteger.ONE)  // i=n+1;         for (int j=n+1 j>=1 i=i.subtract(BigInteger.ONE),j--)             cat=cat.divide(i);         return cat;     }