题目链接:HDU3723
Delta Wave
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 608 Accepted Submission(s): 199
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
Recommend
zhouzeyong
看完题第一感觉是个二维dp 记录第i个位置高度j的方案数
但是数据范围有点大 而且还要用大数 所以不行
仔细想一下 如果横着走的情况是可以再任意地方出现的
所以只要先把横着走的部分去掉 解决上下走的方案这题就完了
上下走的情况很好搞 就是高度每次可以+1,-1 并且高度必须大于等于0
这个东西是卡特兰数 或者直接用组合数学推导出来是 C(2*n,n)-C(2*n,n-1)
然后化简成 C(2*n,n)/(n+1) 这个就是n步上下走的答案
然后 枚举进行k次上下走 那么横着走就是C(n,n-2*k)
最后答案就是 sigma{ C(n,n-2*k) *C(2*k,k)/(k+1) } (0<=k<=n/2)
然后就能很轻松的推出 和式的递推式
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;
public class Main
{
public static void main(String[] args)
{
Scanner cin = new Scanner ( System.in );
int n;
BigInteger[] s=new BigInteger[10005];
BigInteger a,b,mod=BigInteger.TEN;
mod=mod.pow(100);
s[0]=s[1]=BigInteger.ONE;
for(int i=2;i<10001;i++)
{
a=BigInteger.valueOf(2*i+1).multiply(s[i-1]);
b=BigInteger.valueOf(3*i-3).multiply(s[i-2]);
s[i]=a.add(b).divide(BigInteger.valueOf(i+2));
}
while(cin.hasNext())
{
n=cin.nextInt();
System.out.println(s[n].mod(mod));
}
}
}