Train Problem II

这题是一个Catalan数,利用公式h(n)=h(n-1)*(4*n-2)/(n+1),其实还可以用其他卡特兰公式,但这个用起来更简单,但是涉及大数问题,用C写比较麻烦,本人用了最近师哥讲的JAVA写的.

As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway.

Input

The input contains several test cases. Each test cases consists of a number N(1<=N<=100). The input is terminated by the end of file.

Output

For each test case, you should output how many ways that all the trains can get out of the railway.

Sample Input

1
2
3
10

Sample Output

1
2
5
16796


        
  

Hint

The result will be very large, so you may not process it by 32-bit integers.

        
 

JAVA代码:

import java.util.*;
import java.math.*;
public class Main {
	public static void main(String args[]) {
		Scanner cin = new Scanner(System.in);
		BigInteger a,b,c,d,n,s;
		BigInteger[] dp;
		dp=new BigInteger[105];
		dp[1]=new BigInteger("1");
		a=new BigInteger("4");
		b=new BigInteger("2");
		c=new BigInteger("1");
		int i,m;
		for(i=2;i<=100;i++)
		{
			d=BigInteger.valueOf(i);
			n=d.multiply(a).subtract(b);
			s=d.add(c);
			dp[i]=dp[i-1].multiply(n).divide(s);
		}
		while(cin.hasNext())
		{
		    m=cin.nextInt();
		    System.out.println(dp[m]);
		}
	}
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值