你的位置:首页 > 软件开发 > Java > POJ 2084 Game of Connections 卡特兰数

POJ 2084 Game of Connections 卡特兰数

发布时间:2016-08-09 15:00:06
看了下大牛们的,原来这题是卡特兰数,顺便练练java。递归式子:h(0)=1,h(1)=1 h(n)= h(0)*h(n-1) + h(1)*h(n-2) + ... + h(n-1)h(0) (其中n>=2) 打表172 ...

看了下大牛们的,原来这题是卡特兰数,顺便练练java。递归式子:h(0)=1,h(1)=1   h(n)= h(0)*h(n-1) + h(1)*h(n-2) + ... + h(n-1)h(0) (其中n>=2)   打表172MS

import java.math.BigInteger;import java.util.Scanner;public class Main {  public static void main(String[] args) {    Scanner in=new Scanner(System.in);    BigInteger[] a=new BigInteger [205];    a[0]=a[1]=BigInteger.ONE;    for(int i=2;i<=200;i++){      a[i]=BigInteger.ZERO;      for(int j=0;j<i;j++){        a[i]=a[j].multiply(a[i-j-1]).add(a[i]);      }      //System.out.println(a[i]);    }    while(true){      int n=in.nextInt();      if(n==-1)        break;      System.out.println(a[n]);    }  }}

 

海外公司注册、海外银行开户、跨境平台代入驻、VAT、EPR等知识和在线办理:https://www.xlkjsw.com

原标题:POJ 2084 Game of Connections 卡特兰数

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

可能感兴趣文章

我的浏览记录