Delta Wave
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 706 Accepted Submission(s): 228
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.
-- 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 10
100.
Sample Input
3 4
Sample Output
4 9
Source
题意:从(0,0)到(n,0),x方向没前进一格,y方向只能上升、下降一格或者不变。有多少种方案
思路:设n个格子中有k次上升的,那么就有k次下降的,这2k次的排列方案可以看做括号序列的方案数,即卡特兰数,设f[k]表示前这2k个上升下降的排列方案数,g[k]表示总的方案数
<pre name="code" class="java">import java.io.*;
import java.math.BigInteger;
import java.util.Scanner;
class Main
{
public static void main(String[] Args) throws FileNotFoundException
{
InputStream in=System.in;
// InputStream in = new FileInputStream(new File("C:\\Users\\Sky\\Desktop\\1.in"));
Scanner s = new Scanner(in);
int n;
while (s.hasNext())
{
n = s.nextInt();
BigInteger tmp = BigInteger.ONE;
BigInteger ans = BigInteger.ONE;
for (int i = 0; i < n / 2; i++)
{
tmp = tmp.multiply(BigInteger.valueOf(n - 2 * i))
.multiply(BigInteger.valueOf(n - 2 * i - 1))
.divide(BigInteger.valueOf(i + 1)).divide(BigInteger.valueOf(i + 2));
ans=ans.add(tmp);
}
ans=ans.mod(BigInteger.TEN.pow(100));
System.out.println(ans);
}
}
}