combinatorics and memoization