poj2084

题意:一圆环上有2n个点,求两两连线且不交叉的方法数。

分析:catalan数

令h(1)=1,h(0)=1,catalan数满足

递归式:   h(n)= h(0)*h(n-1)+h(1)*h(n-2) + ... + h(n-1)h(0) (其中n>=2)   

另类递归式:   h(n)=((4*n-2)/(n+1))*h(n-1);   

该递推关系的解为:   h(n)=C(2n,n)/(n+1) (n=1,2,3,...)

它的适用情况有:

1、取物2n个,物品分a,b两种,任意时刻手中的a物品数<b物品数,的方法数为h(n)。

2、把(n+2)边形分割成若干个三角形组面积组合的方法数为h(n)。

3、一圆环上有2n个点两两连线不交叉的方法数为h(n)。

View Code
import java.io.*;
import java.util.*;
import java.math.*;

publicclass Main {

publicstaticvoid main(String args[]) throws FileNotFoundException {
//Scanner cin = new Scanner(new FileInputStream("t.txt"));
Scanner cin =new Scanner(new BufferedInputStream(System.in));
BigInteger[] h
=new BigInteger[105];
h[
0] =new BigInteger("1");
h[
1] =new BigInteger("1");
for (int i =2; i <=100; i++)
h[i]
= h[i -1].multiply(BigInteger.valueOf(4* i -2)).divide(
BigInteger.valueOf(i
+1));
while (true) {
int n = cin.nextInt();
if (n ==-1)
break;
System.out.println(h[n]);
}
}
}
posted @ 2011-06-06 21:29  金海峰  阅读(519)  评论(0编辑  收藏  举报