題意:
(from luckycat)
解法:
大數 & 卡塔蘭數。
TAG: Catalan Number, Math, BigNum
注意:
程式碼:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Tittle: 10303 - How Many Trees? | |
* Author: Cheng-Shih, Wong | |
* Date: 2015/06/11 | |
*/ | |
import java.util.*; | |
import java.math.*; | |
public class Main { | |
public static void main( String[] args ) { | |
final int N = 1005; | |
BigInteger[] cat = new BigInteger[N]; | |
Scanner input = new Scanner(System.in); | |
int n; | |
// init | |
cat[1] = BigInteger.ONE; | |
for( int i=1; i<1000; ++i ) | |
cat[i+1] = cat[i].multiply( BigInteger.valueOf(2*(2*i+1)) ).divide( BigInteger.valueOf(i+2) ); | |
// solve | |
while( input.hasNext() ) { | |
n = input.nextInt(); | |
System.out.println(cat[n]); | |
} | |
input.close(); | |
} | |
} |
沒有留言:
張貼留言
任何意見都樂意傾聽