hdu 3723 Delta Wave

Delta Wave hdu 3723

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

解析:首先可以观察到上升、下降位置的个数是一样的。假设有k对上升、下降的位置,那么这k对位置的合法组合数为Cat[k]。Cat为卡特兰数,这个组合问题等价于卡特兰数的经典应用括号化问题。设T[k]为n个位置中有k对上升、下降位置的组合数,这k对位置从n个位置中选出。所以T[k] = C(n,2*k)Cat[k] = C(n,2*k)*C(2*k,k)/(k+1)。这样只需要枚举k即可,sum = T[0]+T[1]+…+T[m] (2*m<=n)。然而n<=10000,C(n,m)无法打表,也不好求。进一步可以推出T[k]/T[k-1] = (n-2*k+1)(n-2*k+2)/(k*(k+1))。显然T[0] = 1,于是逐个递推出来即可。

注意:由于给出数据和取模数据很大,建议用Java定义BigInteger

代码如下:

import java.math.BigInteger;  
import java.util.Scanner;  

public class Main {  
    public static void main(String[] args) {  
        Scanner sc = new Scanner(System.in);  
        BigInteger mod = BigInteger.TEN.pow(100);  
        BigInteger sum = new BigInteger("0");  
        BigInteger t = new BigInteger("0");  
        while (sc.hasNext()) {  
            int n = sc.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));  
        }  
    }  
}  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值