码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-08-25 19:16:24      阅读:290      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   java   os   io   strong   for   

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:


bubuko.com,布布扣



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);
		}
	}
}



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

标签:des   style   http   color   java   os   io   strong   for   

原文地址:http://blog.csdn.net/mowayao/article/details/38824771

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!