题意:就是问你火车出战的方案数。

分析:卡特兰数的模板题,递推公式:a[n]=a[n-1]*(4*n-2)/(n+1).

java代码实现:

import java.util.*;
import java.math.BigInteger;
import java.io.*;

public class Main {
    public static void main(String[] args) {
        BigInteger a[] = new BigInteger[101];
        a[0] = BigInteger.ZERO;
        a[1] = BigInteger.ONE;
        for(int i=2;i<=100;i++) {
            a[i] = a[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1));
        }
        
        Scanner in = new Scanner(System.in);
        
        while(in.hasNext()) {
            int n=in.nextInt();
            System.out.println(a[n]);
        }
    }
} 

 

相关文章:

  • 2021-07-18
  • 2022-02-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-22
  • 2021-06-28
猜你喜欢
  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2021-08-24
  • 2022-12-23
  • 2021-08-03
  • 2021-12-04
相关资源
相似解决方案