首页 > 代码库 > 9D-树形DP

9D-树形DP

 给定n个点(1~n)使他们构成二叉树  求高度大于h 的有多少种

#include <iostream>using namespace std;long long int tbl[36][36];long long int get(int n, int h) {    long long int &ans = tbl[n][h];    if (ans == -1) {        ans = 0;        if (n == 0) ans = 1;        else if(h == 0)        ans = 0;        else         for(int j = 0; j <= n-1; ++j)        ans += get(j, h-1) * get(n-1-j, h-1);    }    return ans;}int main(void){    int n,h;    cin >> n >> h;    for (int i = 0; i <= n; ++i)    fill_n(tbl[i], 36, -1);    cout << get(n, n) - get(n, h-1) << endl;    return 0;}

 

9D-树形DP