Find the fastest way through a factory using recursive and dynamic programming techniques