Home  >  Article  >  Java  >  Java simple Cattleya number code example

Java simple Cattleya number code example

Y2J
Y2JOriginal
2017-04-24 11:59:121746browse

<span style="font-size:24px;">package 卡特兰数;
public class Catalan {
	public static void main(String[] args) {
		int n = 3;
		System.out.println(CatalanProcess(n));
	}
	private static int CatalanProcess(int n) {
		if(n <= 1){
			return 1;
		}
		int[] h = new int[n+1];
		int result = 0;
		h[0] = h[1] = 1;
		for(int i=2 ; i<=n ; i++){
			h[i] = 0;
			for(int j=0 ; j<i ; j++){
				h[i] += (h[j]*h[i-(j+1)]);
			}
		}
		result = h[n];
		return result;
	}

}</span>

The above is the detailed content of Java simple Cattleya number code example. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn