题解 | #有多少个不同的二叉搜索树#
有多少个不同的二叉搜索树
https://www.nowcoder.com/practice/16d23f940a084023b3be6019262589dc
#include <bits/stdc++.h> using namespace std; int a[25], n; int main() { cin >> n; if (n < 3) cout << n << endl; else { a[0] = 1; a[1] = 1; a[2] = 2; for (int i = 3; i <= n; i++) { for (int j = 0; j < i; j++) { a[i] += a[j] * a[i - j - 1]; } } cout << a[n] << endl; } return 0; }