首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

容易Catalan数-hdu-1130-How Many Trees

2013-10-12 
简单Catalan数-hdu-1130-How Many Trees?题目链接:http://acm.hdu.edu.cn/showproblem.php?pid1130题目意

简单Catalan数-hdu-1130-How Many Trees?

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=1130

题目意思:

catalan数模型。求出第n个catalan数。(n<=100)

解题思路:

直接利用catalan数递推h[n]=(4*n-2)/(n+1)*h[n-1] (n>1)

java水过。

代码:

import java.util.*;import java.math.*;public class Main {/** * @param args */static BigInteger []h = new BigInteger[120];static public void init(){h[1]=BigInteger.valueOf(1);h[0]=h[1];for(int i=2;i<=100;i++)h[i]=h[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));}public static void main(String[] args){// TODO Auto-generated method stubinit();Scanner cin=new Scanner(System.in);int n;while(cin.hasNextInt()){n=cin.nextInt();System.out.println(h[n]);}}}


热点排行