Skip to content

Instantly share code, notes, and snippets.

@deque-blog
Created October 19, 2017 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save deque-blog/b1f0a472281d9a2cc8d3033df5852f5c to your computer and use it in GitHub Desktop.
Save deque-blog/b1f0a472281d9a2cc8d3033df5852f5c to your computer and use it in GitHub Desktop.
static long long lazy_map(std::unordered_map<int, long long>& memo, int n)
{
auto& computed = memo[n];
if (computed) return computed;
auto recur = [&](int k) { return lazy_map(memo, k); };
return computed = bst_count(recur, n);
}
long long bst_count_map(int n)
{
std::unordered_map<int, long long> memo;
return lazy_map(memo, n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment