HDU3723-Delta Wave(Catalan数+组合计数)

Delta Wave

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 741    Accepted Submission(s): 243

Problem Description

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:

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 <= 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

题意:可以归纳为:前n个数(0,1,-1)对于每个k <=n都有前缀和大于等于0,且前n项和为0.

思路:先不管0,前n个数相加,总和为0的方案数,很容易看出这是Catalan数,至于0,只要计算一下组合数就行了。然后与Catalan数相结合推出递推公式就行。

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

public class Main {

	private static Scanner in;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		BigInteger MOD = BigInteger.ONE;
		for(int i = 1; i <= 100; i++){
			MOD = MOD.multiply(BigInteger.valueOf(10));
		}

		in = new Scanner(System.in);
		while(in.hasNextInt()){
			int n = in.nextInt();
			BigInteger ret = BigInteger.ONE,now = BigInteger.ONE;
			for(int i = 1; i+i <= n; i++){
				now = now.multiply(BigInteger.valueOf(n-2*i+1)).multiply(BigInteger.valueOf(n-2*i+2)).divide(BigInteger.valueOf(i*i+i));
				ret = ret.add(now);
			}
			ret = ret.mod(MOD);
			System.out.println(ret);
		}
	}
}
时间: 2024-10-08 19:25:30

HDU3723-Delta Wave(Catalan数+组合计数)的相关文章

LA 5092 &amp;&amp; hdu 3723 Delta Wave (卡特兰数)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=3723 and http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20568 题意:有种折线每向右延伸一个单位长度,高度要么不变,要么加1,要么减1.而且任何时刻高度不能低于0.求这种折线最终高度为0的情况总数. 分析:由于任何时刻斜向上的线不小于斜向下的线的数目,而且最终相等,,,,,卡特兰数模型.卡特兰数资料 若有i条斜向上的线,那

HDU4372-Count the Buildings(第一类Stirling数+组合计数)

Count the Buildings Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 528    Accepted Submission(s): 171 Problem Description There are N buildings standing in a straight line in the City, numbere

HDU 3723 Delta Wave(默慈金数)

传送门 Delta Wave Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1160    Accepted Submission(s): 370 Problem Description A delta wave is a high amplitude brain wave in humans with a frequency of 1

uva 1478 - Delta Wave(递推+大数+卡特兰数+组合数学)

题目链接:uva 1478 - Delta Wave 题目大意:对于每个位置来说,可以向上,水平,向下,坐标不能位负,每次上下移动最多为1, 给定n问说有多少种不同的图.结果对10100取模. 解题思路:因为最后都要落回y=0的位置,所以上升的次数和下降的次数是相同的,并且上升下降的关系满足出栈入栈的关系.即卡特兰数. 所以每次枚举i,表示有i个上升,i个下降,用组合数学枚举出位置,然后累加求和. C(2?in)?f(i)=C(2?i?2n)?f(i?1)?(n?2?i+1)?(n?2?i+2)

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

Description 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 dis

[Catalan数]1086 栈、3112 二叉树计数、3134 Circle

1086 栈 2003年NOIP全国联赛普及组 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 栈是计算机中经典的数据结构,简单的说,栈就是限制在一端进行插入删除操作的线性表. 栈有两种最重要的操作,即pop(从栈顶弹出一个元素)和push(将一个元素进栈). 栈的重要性不言自明,任何一门数据结构的课程都会介绍栈.宁宁同学在复习栈的基本概念时,想到了一个书上没有讲过的问题,而他自己无法给出答案,所以需要你的帮忙 宁宁考虑的

特殊计数序列——Catalan数

Catalan数 前10项 \(1,1,2,5,14,42,132,429,1430,4862\) (注:从第\(0\)项起) 计算式 \(C_n=\frac{1}{n+1}\dbinom{2n}{n}\) \(C_{n+1}=\sum_{i=0}^nC_iC_{n-i}\) \(C_n=\dbinom{2n}{n}-\dbinom{2n}{n-1}\) \(C_n=\frac{4n-2}{n+1}C_{n-1}\) 组合意义 1.由\(n\)个\(+1\)和\(n\)个\(-1\)构成的\(2

(转载)Catalan数——卡特兰数

Catalan数--卡特兰数 今天阿里淘宝笔试中碰到两道组合数学题,感觉非常亲切,但是笔试中失踪推导不出来后来查了下,原来是Catalan数.悲剧啊,现在整理一下 一.Catalan数的定义令h(1)=1,Catalan数满足递归式:h(n) = h(1)*h(n-1) + h(2)*h(n-2) + ... + h(n-1)h(1),n>=2该递推关系的解为:h(n) = C(2n-2,n-1)/n,n=1,2,3,...(其中C(2n-2,n-1)表示2n-2个中取n-1个的组合数) 问题描

HDU4675-GCD of Sequence(数论+组合计数)

GCD of Sequence Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 949    Accepted Submission(s): 284 Problem Description Alice is playing a game with Bob. Alice shows N integers a1, a2, -, aN, an