卡特兰数:poj 2084 Game of Connections+hdu 1023

poj 2084:Game of Connections

题目链接:http://poj.org/problem?id=2084

解题思路:卡特兰数,打表+大数据跑Java

参考代码:

import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String [] args){
		Scanner cin=new Scanner(System.in);
		BigInteger[] h=new BigInteger[110];
		h[0]=new BigInteger("1");
		h[1]=new BigInteger("1");
		for(int i=2;i<110;i++)
			h[i]=h[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));
		while(cin.hasNext()){
			int n=cin.nextInt();
			if(n==-1) break;
			System.out.println(h[n]);
		}
	}	
}



文献转载:

http://www.cnblogs.com/jackge/archive/2013/05/19/3086519.html

http://blog.csdn.net/hackbuteer1/article/details/7450250

维基百科:http://zh.wikipedia.org/wiki/%E5%8D%A1%E5%A1%94%E5%85%B0%E6%95%B0






补充情形:

问题1:12个高矮不同的人,排成两排,每排必须是从矮到高排列,而且第二排比对应的第一排的人高,问排列方式有多少种?

参考题解:http://blog.csdn.net/hackbuteer1/article/details/7450250

hdu 1023 : Train Problem II

问题2:火车按照123…n的次序驶入火车站,问驶出站台的情况种数?

等价于出栈顺序问题:n个数入栈求出栈的情况(栈:先入后出)

参考代码(java)

import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
	public static void main(String [] args){
		Scanner cin=new Scanner(System.in);
		BigInteger[] h=new BigInteger[105];
		h[1]=new BigInteger("1");
		h[2]=new BigInteger("2");
		for(int i=3;i<105;i++)
			h[i]=h[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));
		while(cin.hasNext()){
			int n=cin.nextInt();
			System.out.println(h[n]);
		}
	}	
}




  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值