UV 10007 & amp; hdu 1131 Count the Trees (catlands)
Count the Trees
Time Limit:3000 MS
Memory Limit:0 KB
64bit IO Format:% Lld & % lluSubmitStatus
Description
Another common social inability is known as ACM (Abnormally Compulsive Meditation ). this psychological disorder is somewhat common among programmers. it can be described as the temporary (although frequent) loss of the faculty of speech when the whole power of the brain is applied to something extremely interesting or challenging.
Juan is a very gifted programmer, and has a severe case of ACM (he even participant ipated in an ACM world championship a few months ago ). lately, his loved ones are worried about him, because he has found a new exciting problem to exercise his intellectual powers, and he has been speechless for several weeks now. the problem is the determination of the number of different labeled binary trees that can be built using exactlyNDifferent elements.
For example, given one elementA, Just one binary tree can be formed (usingAAs the root of the tree). With two elements,AAndB, Four different binary trees can be created, as shown in the figure.
If you are able to provide a solution for this problem, Juan will be able to talk again, and his friends and family will be forever grateful.
Input The input will consist of several input cases, one per line. Each input case will be specified by the number
N(
1 ≤ n ≤300) Of different elements that must be used to form the trees. A number 0Will mark the end of input and is not to be processed.
Output For each input case print the number of binary trees that can be built using
NElements, followed by a newline character.
Sample Input
1210250
Sample Output
146094932480075414671852339208296275849248768000000
Question: Give You n points and ask how many different trees can be formed.
Resolution: catlan number.
AC code:
#include
#include
#define SIZE 200#define MAXN 302#define BASE 10000using namespace std;int Canlan[MAXN][SIZE];int temp[SIZE];void A(int n){ memcpy(temp, Canlan[n], sizeof(temp)); int e = 0; for(int fac = n; fac>0; --fac) { for(int i = SIZE-1, remain = 0; i>=0; --i) { e = temp[i] * fac + remain; temp[i] = e % BASE; remain = e / BASE; } } memcpy(Canlan[n], temp, sizeof(int)*SIZE);}void multiply(int elem){ for(int i=SIZE-1, remain = 0; i >= 0; --i) { remain = temp[i] * elem + remain; temp[i] = remain % BASE; remain = remain / BASE; } return;}void divide(int elem){ int i; for(i=0; i