Question: In the tree composed of n elements, it is not the number of Binary Trees.
Analysis: combination, count, and Qaran number.
The number of Binary Trees composed of n elements is the Cn-1 of the qataran number. There is a recurrence relationship as follows:
The number of all trees composed of n elements is the number sn of the catataran number. There is a recursive relationship as follows:
Catlan Data Reference: http://blog.csdn.net/mobius_strip/article/details/39229895
Chaocatran Data Reference: http://mathworld.wolfram.com/SuperCatalanNumber.html
Output S (n)-C (n-1.
Note: The information of the number of cataras is better than that of the number of sub-accounts.
#include <iostream>#include <cstdlib>using namespace std;long long C[30] = {0};long long S[30] = {0}; int main(){S[0] = S[1] = S[2] = 1;for (int i = 3 ; i < 30 ; ++ i)S[i] = (3*(2*i-3)*S[i-1]-(i-3)*S[i-2])/i;C[0] = C[1] = 1;for (int i = 2 ; i < 30 ; ++ i)for (int j = 0 ; j < i ; ++ j)C[i] += C[j]*C[i-j-1];int n;while (cin >> n)cout << S[n]-C[n-1] << endl;return 0;}
Ultraviolet A 10312-expression bracketing