LA 5092 && hdu 3723 Delta Wave (Cattleya number)

Source: Internet
Author: User
Tags polyline

Title: http://acm.hdu.edu.cn/showproblem.php?pid=3723 and http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=20568

Test instructions: There is a kind of polyline that extends one unit length to the right, the height is either unchanged, or 1 or minus 1. And the height of any moment must not be less than 0. The total number of cases where the final height of this polyline is 0.

Analysis: The oblique upward line at any moment is not less than the number of oblique downward lines, and ultimately equal,,,,, Cattleya number model. Cattleya number of data if there is a diagonal upward line, then there will be an I diagonal downward line, the scheme number is Catalan (i), because there are n-2*i horizontal straight lines, the horizontal line arbitrarily put the number of schemes is C (n,n-2*i) =c (n,2*i), So the total scheme number of lines with I skew upward is: S (i) =c (n,2*i) *catalan (i). However, from the 0~N/2 enumeration of oblique lines, and then each individual calculation, time complexity is relatively high, can be considered directly by S (i-1) calculation s (i), by simplifying can be obtained s (i) =s (i-1) * (n-2*i+2) * (n-2*i+1)/(i* (i+1)).

Code:

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

public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext())
		{
			int n=cin.nextInt();
			BigInteger ans=(BigInteger.ONE);
			BigInteger cur=(BigInteger.ONE);
			for(int i=1;i<=n/2;i++)
			{
				cur=cur.multiply(BigInteger.valueOf(n-2*i+2)).multiply(BigInteger.valueOf(n-2*i+1));
				cur=cur.divide(BigInteger.valueOf(i*i+i));
				ans=ans.add(cur);
			}
			System.out.println(ans.mod(BigInteger.TEN.pow(100)));
		}
	}

}

LA 5092 && hdu 3723 Delta Wave (Cattleya number)

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.