HDU - 3723 Delta Wave 卡特兰数

题目:让你输出从点(0,0)到点(N,0)一共有多少种方法,点(r,c)可以到点(r,c+1),(r+1,c+1),(r-1,c+1),但是不能走到x轴的下方。

下图是N=4的方法


Sample Input
3
4
Sample Output
4
9


思路:行数要么+1,要么+0,要么-1,因为不能到x轴的下方,所以任意时刻+1的次数都要大于等于-1的次数,所以就是卡特兰数了呀。

设总的+1的次数为i

ans+=C(n,2*i)*h(i-1)*(4*i-2)/(i+1)

代码:

import java.math.*;
import java.util.*;

public class Main {
	static BigInteger one = BigInteger.ONE;
	static BigInteger two =BigInteger.valueOf(2);
	static BigInteger zero = BigInteger.ZERO;
	static BigInteger ten = BigInteger.TEN;
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		int n;
		while(cin.hasNext()){
			n=cin.nextInt();
			BigInteger ans=one,h=one,C=one;
			int y=0;
			for(int i=1;2*i<=n;i++){
				C=C.multiply(BigInteger.valueOf(n-y)).divide(BigInteger.valueOf(y+1));
				y++;
				C=C.multiply(BigInteger.valueOf(n-y)).divide(BigInteger.valueOf(y+1));
				y++;
				h=h.multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));
			//	System.out.println(C+"  "+h);
				ans=ans.add(h.multiply(C));
			}
			ans=ans.mod(ten.pow(100));
			System.out.println(ans);
		}
		cin.close();
	}
}



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值