HDU3723-Delta wave (Catalan count + combined count)

Source: Internet
Author: User
Delta Wave Time Limit: 6000/3000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 741 accepted submission (s): 243


Problem descriptiona 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.
Inputthere are no more than 20 test cases. There is only one line for each case, containing an integer N (2 <n <= 10000)

 
Outputoutput one line for each test case. For the answer may be quite huge, you need only output the answer module 10100.
Sample Input
34
 
Sample output
49
It can be summarized as follows: The first N number (0, 1,-1) has a prefix and greater than or equal to 0 for each k <= n, and the first N is 0. idea: no matter the number of 0, the number of the first N is added, and the total number is 0. It is easy to see that this is the number of Catalan. As for 0, you just need to calculate the number of combinations. Then, the recursive formula can be used in combination with the catalan number.
import java.util.*;import java.math.*;public class Main {private static Scanner in;public static void main(String[] args) {// TODO Auto-generated method stubBigInteger MOD = BigInteger.ONE;for(int i = 1; i <= 100; i++){MOD = MOD.multiply(BigInteger.valueOf(10));}in = new Scanner(System.in);while(in.hasNextInt()){int n = in.nextInt();BigInteger ret = BigInteger.ONE,now = BigInteger.ONE;for(int i = 1; i+i <= n; i++){now = now.multiply(BigInteger.valueOf(n-2*i+1)).multiply(BigInteger.valueOf(n-2*i+2)).divide(BigInteger.valueOf(i*i+i));ret = ret.add(now);}ret = ret.mod(MOD);System.out.println(ret);}}}



HDU3723-Delta wave (Catalan count + combined count)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.