recursion with memorization