裸卡兰特数
2015-10-23 14:37
246 查看
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1130
卡兰特数:令h(1)=1,h(0)=1,catalan数满足递归式: //h(n)=(4*n-2)/(n+1)*h(n-1);
JAVA代码
import java.math.BigInteger;
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
BigInteger[] arr = new BigInteger[1100];
arr[0] = BigInteger.ONE;
arr[1] = BigInteger.ONE;
BigInteger four = BigInteger.valueOf(4);
BigInteger two = BigInteger.valueOf(2);
BigInteger one = BigInteger.valueOf(1);
for(int i=2;i<1001;i++){
arr[i] = arr[i-1].multiply(four.multiply(BigInteger.valueOf(i)).subtract(two)).divide(BigInteger.valueOf(i).add(one));
}
int pos;
while(in.hasNext()){
pos = in.nextInt();
System.out.println(arr[pos]);
}
}
}
卡兰特数:令h(1)=1,h(0)=1,catalan数满足递归式: //h(n)=(4*n-2)/(n+1)*h(n-1);
JAVA代码
import java.math.BigInteger;
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
BigInteger[] arr = new BigInteger[1100];
arr[0] = BigInteger.ONE;
arr[1] = BigInteger.ONE;
BigInteger four = BigInteger.valueOf(4);
BigInteger two = BigInteger.valueOf(2);
BigInteger one = BigInteger.valueOf(1);
for(int i=2;i<1001;i++){
arr[i] = arr[i-1].multiply(four.multiply(BigInteger.valueOf(i)).subtract(two)).divide(BigInteger.valueOf(i).add(one));
}
int pos;
while(in.hasNext()){
pos = in.nextInt();
System.out.println(arr[pos]);
}
}
}
相关文章推荐
- TCP/IP、Http、Socket的区别
- 垃圾回收算法
- ELK学习3_使用redis+logstash+elasticsearch+kibana快速搭建日志平台
- activity启动flag和activity属性分析
- 脑科学发展史
- 建行E商贸通支付开发系列之四(测试环境搭建)
- 学习Android推送功能笔记(9)---搭建推送平台
- leetcode summartRanges
- 淘宝可以传照片搜索商品,verygood.雅客VC多味水果糖
- Intersection of Two Linked Lists - LeetCode
- 裸卡兰特数
- vim 折叠的用法
- Centos 6.5 安装Xrdp 远程桌面
- Json format to send notification from Parse
- wpf笔记(二)
- LeetCode 30: Substring with Concatenation of All Words
- lua程序设计
- opencv 移植 S3C2440
- JAVA设计模式(16) —<行为型>迭代子模式(Iterator)
- android unable to resolve static method ****: 解决方法