Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的

Posted by flyingfish at 2006-10-06 18:17:01 on Problem 1737
import java.math.*;
import java.util.*;

public class Main
{
	static final int Max = 51;
	static long pow2[], C[][];
	static BigInteger num[];
	
	public static void init()
	{
		pow2 = new long[Max];
		C = new long[Max][Max];
		pow2[0] = 1;
		int i, j;
		for(i = 1;i < Max;++ i) pow2[i] = pow2[i-1] * 2;
		for(i = 0;i < Max;++ i) C[i][0] = C[i][i] = 1;
		for(i = 1;i < Max;i ++)
			for(j = 1;j < i;j ++)
				C[i][j] = C[i-1][j-1] + C[i-1][j];
		
		num = new BigInteger[Max];
		num[1] = BigInteger.valueOf(1);
		for(i = 2;i < Max;i ++)
		{
			num[i] = BigInteger.valueOf(0);
			for(j = 1;j < i;j ++)
			{
				BigInteger tmp = BigInteger.valueOf(1);
				tmp = tmp.multiply(num[j]);
				tmp = tmp.multiply(num[i-j]);
				tmp = tmp.multiply(BigInteger.valueOf(pow2[j] - 1));
				tmp = tmp.multiply(BigInteger.valueOf(C[i-2][j-1]));
				num[i] = num[i].add(tmp);
			}
		}
	}
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		init();
		while(sc.hasNextInt())
		{
			int n = sc.nextInt();
			System.out.println(num[n]);
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator