Path counting recursive algorithm implemented with dynamic programming methodology