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)