Std::vector prices, which says do multiplication 1 first, followed by multiplication 3, and then finally multiplication 2. Here is some example C++ code that demonstrates a recursive strategy for generating all possible ways to cut a rod of length n into pieces: In most cases we will want to use a recursive strategy for generating all possible configurations, since our first goal is the write a recursive solution for the optimization problem. To construct the loop in the generic search algorithm we have to have a strategy for systemically generating all possible configurations. In the rod cutting example the value of a configuration is the total over all the pieces in the configuration of the value of each piece. The second thing going on here is that we have to be able to evaluate each configuration to assign it a value. ![]() In the rod cutting problem this is the list of all possible ways that you can cut the rod into smaller pieces. ![]() The first thing going on here is a loop that runs a search in a space of possible configurations. Here is the psuedocode for a generic optimization problem of the type we are studying in this chapter: For example, in the rod cutting problem we had the goal of maximizing the income we could obtain by cutting a long rod into smaller pieces and selling those pieces separately. ![]() Besides learning about dynamic programming in chapter 14 we are also looking at various examples of optimization problems.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |