HDU 1023

卡特兰数。把进栈看成是+1,出栈看成是-1,任何时候部分和都有a1+a2+....ak>=0。求这样的数列的个数。这明显是卡特兰数的一个解释嘛。在《组合数学》这本书就有这样的原本的证明。

import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Scanner;

public class Main{
	public static void main(String args[]){
		Scanner in= new Scanner(System.in);
		BigDecimal []Can=new BigDecimal[110];
		BigDecimal B,C,D;
		Can[1]=new BigDecimal(1);
		for(int i=2;i<110;i++){
			B=new BigDecimal(4*i-2);
			C=new BigDecimal(i+1);
			D=Can[i-1].multiply(B);
			Can[i]=D.divide(C);
		}
		while(in.hasNext()){
			int n=in.nextInt();
			System.out.println(Can[n]);
		}
	}
}

  

  

时间: 2024-10-13 13:25:19

HDU 1023的相关文章

HDU 1023 Catalan数+高精度

链接:HDU 1023 /**************************************** * author : Grant Yuan * time : 2014/10/19 15:51 * source : HDU 1023 * algorithm : Catalan数+高精度 * ***************************************/ import java.io.*; import java.math.*; import java.util.*;

hdu 1023 Train Problem II

卡特兰数的应用 :卡特兰数参考kuangbing总结http://www.cnblogs.com/kuangbin/archive/2012/03/21/2410516.html. 大数的运算 hdu题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1023 1 #include<algorithm> 2 #include<stdlib.h> 3 #include<string.h> 4 #include<iostream

HDU 1023 Traning Problem (2) 大数卡特兰数

用java做就很好做了 套公式就可以了 import java.io.*; import java.util.*; import java.math.BigInteger; public class Main { public static void main(String args[]) { BigInteger[] a = new BigInteger[101]; a[0] = BigInteger.ZERO; a[1] = BigInteger.valueOf(1); for(int i

Train Problem II HDU 1023 卡特兰数

Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasing order, how many orders that all the trains can get out of the railway. Input The input contains se

HDU 1023 Train Problem II (卡特兰数,经典)

题意:给出一个数字n,假设火车从1~n的顺序分别进站,求有多少种出站序列. 思路:卡特兰数的经典例子.n<101,用递推式解决.需要使用到大数.n=100时大概有200位以下. 1 #include <bits/stdc++.h> 2 using namespace std; 3 const int N=101; 4 vector<string> vect; 5 void _mult(string num1, string num2, string &result )

hdu 1023 卡特兰数+高精度

Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Station want to know if all the trains come in strict-increasi

hdu 1023 卡特兰数

import java.math.BigInteger; import java.util.Scanner; public class Main{ public static void main(String args[]){ Scanner in = new Scanner(System.in); BigInteger[] a = new BigInteger[105]; for(int i = 0;i < 105;i++){ a[i] = new BigInteger("1"

HDU——1023 Train Problem II

Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 9701    Accepted Submission(s): 5210 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train Stat

C - Train Problem II——(HDU 1023 Catalan 数)

传送门 Train Problem II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7616    Accepted Submission(s): 4101 Problem Description As we all know the Train Problem I, the boss of the Ignatius Train