根据规则可以看出来就是n的卡特兰数乘二
import java.math.BigInteger;import java.util.Scanner;public class Main{ public static void main(String[] args) { Scanner in=new Scanner(System.in); int n=0,i=0,cas=0; BigInteger[] a=new BigInteger[50]; a[0]=BigInteger.ONE; for(i=1;i<=36;i++) { a[i]=a[i-1].multiply(BigInteger.valueOf(4*i-2)).divide(BigInteger.valueOf(i+1)); a[i-1]=a[i-1].multiply(BigInteger.valueOf(2)); } while(in.hasNextInt()) { n=in.nextInt(); if(n==-1) break; cas++; System.out.print(cas+" "+n+" "); System.out.println(a[n]); } in.close(); }}
版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/