Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
long long bst_count_classic(int n)
{
if (n <= 1) return 1;
std::vector<long long> memo(n+1, 0);
memo[0] = memo[1] = 1;
for (int k = 2; k <= n; ++k)
for (int i = 0; i < k; ++i)
memo[k] += memo[i] * memo[k-i-1];
return memo.back();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment