UVA - 1478 Delta Wave (大数+卡特兰数)

Description

Download as PDF

A delta wave is a high amplitude brain wave in humans with a frequency of 1 - 4 hertz which can be recorded with an electroencephalogram (EEG) and is usually associated with slow-wave sleep (SWS).

- from Wikipedia

The researchers have discovered a new kind of species called ``otaku", whose brain waves are rather strange. The delta wave of an otaku's brain can be approximated by a polygonal line in the 2D coordinate system. The line is a route from point (0, 0) to (N, 0), and it is allowed to move only to the right (up, down or straight) at every step. And during the whole moving, it is not allowed to dip below the y = 0 axis.

For example, there are the 9 kinds of delta waves for N = 4:

\epsfbox{p5028.eps}

Given N, you are requested to find out how many kinds of different delta waves of otaku.

Input

There are no more than 20 test cases. There is only one line for each case, containing an integer N (2 < N$ \le$10000)

Output

Output one line for each test case. For the answer may be quite huge, you need only output the answer module 10100.

Sample Input

3 
4

Sample Output

4 
9
题意:从坐标(0, 0)到(n, 0)的折线,这条折线每向右延伸一个单位长度,高度要么不变,要么+1,要么-1,已知n,求这种折线种数
思路:我们知道上升和下降的次数要一样,而这就像卡特兰数的入栈出栈次序一样,所以我们从n中选出2k次进行类出栈模拟,
那么ans[k] = C[n][2k]*C[2k][k]/(k+1),然后我们可以相除两式递推出结果是ans[k] = ans[k-1]*(n-2*k+2)*(n-2*k+1)/(k*(k+1)) 
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 mod = BigInteger.ONE;
		for (int i = 1; i <= 100; i++)
			mod = mod.multiply(BigInteger.valueOf(10));
		while (cin.hasNext()) {
			int n = cin.nextInt();
			if (n == 0)
				break;
			BigInteger it = BigInteger.ONE;
			BigInteger ans = BigInteger.ONE;
			for (int i = 0; i < n/2; i++) {
				it = it.multiply(BigInteger.valueOf((n-2*i)*(n-2*i-1)));
				it = it.divide(BigInteger.valueOf((i+1)*(i+2)));
				ans = ans.add(it);
			}
			System.out.println(ans.mod(mod));
		}
	}
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值