#题解# 有多少个不同的二叉搜索树
有多少个不同的二叉搜索树
https://www.nowcoder.com/practice/16d23f940a084023b3be6019262589dc?tpId=230&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3Fpage%3D1%26tab%3D%25E7%25AE%2597%25E6%25B3%2595%25E7%25AF%2587%26topicId%3D230
准备春招,继续做题了。
#include <bits/stdc++.h>
int main(int argc, char *argv[]) {
int node_num;
std::cin >> node_num;
std::vector<int> dp(node_num + 1, 0);
dp[0] = 1;
dp[1] = 1;
// 节点数
for (int i = 2; i <= node_num; ++i) {
// 以编号j的结点作为头节点
for (int j = 1; j <= i; ++j) {
dp[i] += dp[j - 1] * dp[i - j];
}
}
std::cout << dp[node_num] << std::endl;
return 0;
}