During self-guided behaviors animals rapidly identify the constraints of the problems they face and adaptively employ appropriate cognitive strategies and heuristics to solve these problems 1,2 .This ability is currently an area of active investigation in artificial intelligence 3 . Recent work in computer science has suggested that this type of flexible problem solving could be achievable with metaheuristic approaches in which specific algorithms are selected based upon the identified demands of the problem to be solved 4,5,6,7 . Investigating how animals employ such metaheuristics while solving self-guided natural problems is a fertile area for biologically inspired algorithm development. Here we show that animals adaptively shift cognitive resources between sensory and memory systems during natural behavior to optimize performance under uncertainty. We demonstrate this using a new, laboratory-based discovery method to define the strategies used to solve a difficult optimization scenario, the stochastic "traveling salesman" problem 5,8,9 . Using this system we precisely manipulated the strength of prior information available to animals as well as the complexity of the problem. We find that rats are capable of efficiently solving this problem, even under conditions in which prior information is unreliable and the space of possible solutions is large. We compared animal performance to a Bayesian search and found that performance is consistent with a metaheuristic approach that adaptively allocates cognitive resources between sensory processing and memory, enhancing sensory acuity and reducing memory load under conditions in which prior information is unreliable. Our findings set the foundation for new approaches to understand the neural substrates of natural behavior as well as the rational development of biologically inspired metaheuristic approaches for complex real-world optimization.