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
Source
2010 Asia Tianjin Regional Contest
Recommend
zhouzeyong | We have carefully selected several similar problems for you: 3720 3729 3728 3727 3726
卡特兰数(默慈金数)
思路:
学校要学java,顺便写一下大数
import java.util.*;
import java.math.*;
import java.io.*;
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 input = new Scanner(System.in);
int n;
while(input.hasNext()) {
n = input.nextInt();
BigInteger ans = one,h = one,C = one;
int cnt = 0;
for(int i = 1;i <= n / 2;i++)
{
C = C.multiply(BigInteger.valueOf(n - cnt)).divide(BigInteger.valueOf(cnt + 1));
cnt++;
C = C.multiply(BigInteger.valueOf(n - cnt)).divide(BigInteger.valueOf(cnt + 1));
cnt++;
h = h.multiply(BigInteger.valueOf(4 * i - 2)).divide(BigInteger.valueOf(i + 1));
ans = ans.add(h.multiply(C));
}
ans = ans.mod(ten.pow(100));
System.out.println(ans);
}
}
}