HDU 3723 Delta Wave(默慈金数)

来源:互联网 发布:西科在线网络教育 编辑:程序博客网 时间:2024/05/16 15:03

传送门

Delta Wave

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1160    Accepted Submission(s): 370


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


题目大意:
在一个无限大的“网格”上,限定“每步只能向右移动一格(可以向右上、右下横向向右),并禁止移动到y=0以下的地方”,让你求以这种走法用n步从(0,0)移动至(n,0)的可能形成的路径的总数。
解题思路:
其实这个题目就是让我们求 n 的默慈金数,默慈金数是在数学中,一个给定的数n的默慈金数是“在一个圆上的n个点间,画出彼此不相交的弦的全部方法的总数”,也可以理解为上述题意中的方式。其公式为 Mn=(2n+1)Mn1+3(n1)Mn2n+2
还可以写为:
Mn=n/2i=0C(n,2i)Catalan(i)

这个题目的数据范围比较大,所以采用 Java 来做,然后就是取余的时候需要注意不能在中间取余,因为有除法,需要求逆元(好像还有异常,不是很明白),所以为了省事儿就直接在左后取模就行了。

import java.io.*;import java.math.BigDecimal;import java.math.BigInteger;import java.util.Calendar;import java.util.HashSet;import java.util.Scanner;import java.util.Set;public class Main{    public static void main(String args[]){        BigInteger a[] = new BigInteger[100005];        final BigInteger MOD = BigInteger.valueOf(10).pow(100);        a[1] = BigInteger.ONE;        a[2] = BigInteger.valueOf(2);        for(int i=3; i<10005; i++){            a[i] = ( a[i-1].multiply(BigInteger.valueOf(2*i+1)).add(a[i-2].multiply(BigInteger.valueOf(3*i-3))) ).divide(BigInteger.valueOf(i+2));        }        Scanner in = new Scanner(System.in);        int n;        while(in.hasNextInt()){            n = in.nextInt();            System.out.println(a[n].mod(MOD));        }    }}
0 0
原创粉丝点击