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.
-- 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.
3 4
4 9
/*题意:从起始点(0,0)到终止点(n,0)总共有多少种走法*/
/*思路:首先此题用到的思路是卡特兰公式,推一下结论瞬间觉得理解清楚了好多。首先我们明确最基本的卡特兰推论c(2n, n)/n+1, 那么对于此题我们的起点和终止点始终在一条水平线上,那么很容易想到向上走k次就需要向下走k次,k+k <=n,小于的原因是可能会直走,那么此时会产生一个组合数也就是判断哪k次上升哪k次下降即用到数学公式c(n, 2k)说明n个点有2k个会向上向下,那么h(k) = c(n,2k) * c(2k, k)/k+1,(2k中有k个向上或者向下),此时h(k-1) = c(n, 2k - 2) * c(2k - 2, k - 1)/n, 通过运算让h(k)与h(k-1)关系表达出来。h(k) = h(k-1) * (n - 2 * k + 1) * (n - 2 * k + 2) / (k * (k + 1));*/
import java.util.*;
import java.math.BigInteger;
public class Main {
public static void main(String [] args){
Scanner in = new Scanner(System.in);
BigInteger mod = BigInteger.TEN.pow(100); //这里是因为最终题目要求对10^100取模
BigInteger sum;
BigInteger t;
while(in.hasNext()){
int n = in.nextInt();
sum = BigInteger.ONE;
t = BigInteger.ONE;
for(int k = 1; k + k <= n; k++){
t = t.multiply(BigInteger.valueOf((n-2*k+1)*(n-2*k+2))).divide(BigInteger.valueOf(k*(k+1)));
sum = sum.add(t);
}
System.out.println(sum.mod(mod));
}
}
}