hdu 3723 Delta Wave (catalan数+结合数学)

hdu 3723 Delta Wave (catalan数+组合数学)

Delta Wave

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 626    Accepted Submission(s): 203


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:


hdu    3723    Delta Wave   (catalan数+结合数学)



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
 

Source
2010 Asia Tianjin Regional Contest


思路:
将'/'、'\'单独拿出来看的话,就是catalan数模型,然后就是与'-'组合就够了。不过这题坑的一点就是算catalan数或者组合数都不能用阶层来算,因为10000!太大了 ,java也保存不下。比赛时公式都推出来,一直WA,就是被这个给卡了,所以要catalan数和组合数的递推公式

ps:java提交不能放在包里提交,不然一直WA。。。

代码:
import java.util.*;
import java.math.*;

public class Main
{

	public static void main(String[] args) 
	{
		// TODO Auto-generated method stub
		Scanner cin=new Scanner(System.in);
		int i,t,n;
		BigInteger mod,ans,b;
		mod=BigInteger.valueOf(1);
		for(i=1;i<=100;i++)
		{
			mod=mod.multiply(BigInteger.valueOf(10));
		}
        while(cin.hasNext())
        {
        	n=cin.nextInt();
        	ans=BigInteger.valueOf(1);
        	b=BigInteger.valueOf(1);
        	for(i=1;i<=n/2;i++)
        	{
        		b=b.multiply(BigInteger.valueOf((n-2*i+2)*(n-2*i+1))).divide(BigInteger.valueOf((i+1)*i));
        		ans=ans.add(b);
        		ans=ans.mod(mod);
        	}
        	System.out.println(ans);
        }
	}

}