Developing a mathematical model for planning health and population programs through the application of dynamic programming