HDU1131 Java大数

题意:卡特兰数+n!

java!

View Code
 1 import java.math.BigInteger;

 2 import java.util.*;

 3 

 4 public class HDU1131{

 5     public static void main( String args[] ){

 6         int n;

 7         Scanner cin=new Scanner(System.in);

 8         BigInteger h[]=new BigInteger[ 105 ];

 9         h[ 0 ]=h[ 1 ]=BigInteger.ONE;

10         for( int i=2;i<=100;i++ ){

11             h[ i ]=BigInteger.ZERO;

12             for( int j=0;j<i;j++ ){

13                 h[ i ]=h[ i ].add(h[ j ].multiply( h[ i-1-j ] ));

14             }

15         }//Catalan number

16         BigInteger fac[]=new BigInteger[ 105 ];

17         fac[ 1 ]=BigInteger.ONE;

18         for( int i=2;i<=100;i++ )

19             fac[ i ]=fac[ i-1 ].multiply( BigInteger.valueOf(i) );//n!

20         while( cin.hasNext() ){

21             n=cin.nextInt();

22             if( n==0 ) break;

23             System.out.println( fac[n].multiply(h[n]));

24         }    

25     }

26 }

 

你可能感兴趣的:(java)