The convention to follow is that you first check the entry above you. List entry as a pair of integers in the form i, j and in the order they are visited during the backtracking (for each answer, enter two integers with a comma between them, no spaces anywhere). What are they? Of these, the first one is obviously 4,10. Only six table entries need to be accessed to obtain the choice vector. 1 0 0 1 1 Question 6 20 pts In order to obtain the previous answer, you did not need to inspect all the entries in the table. If we had a capacity of 10, and were allowed to choose among only the first four objects, what is the best profit that could be achieved? 18 Write down the choice vector for this (sub) problem. Question 4 20 pts What is the optimal profit and choice vector for a knapsack of capacity 13? Profit = 24 Choice vector 1 2 3 4 5 0 1 1 0 0 Question 5 15 pts The dynamic programming algorithm also allows you to solve for problems with smaller capacity and fewer objects Use the same table to answer the following questions. The thumb-rule for counting ways is that you add up instead of finding max.Given the following 0/1 knapsack problem: 5 objects, knapsack capacity 13 For objects 1,2,3,4,5 the weight vector is and the profit vector is Build the dynamic programming table. The thumb-rule for dimensions is that another constraint in the sack or dimension in the items means another dimension in the formula. The first one is to focus on what we call the core of the problem, namely, a knapsack problem. There are many ways to look at these problems and to define the states T and S. We describe an algorithm for the 0-1 knapsack problem (KP), which relies mainly on three new ideas. ![]() Number of ways to get exactly value y using exactly z items is the sum of T for all j Let S be the number of ways in which the first i items can be arranged with exactly weight j, value k, and l items. w+w+.wĬounting number of ways to get an exact value with an exact number of items Loop j from 1 to max possible weight which is the sum of all weights, e.g. Loop i from 1 to n and be consistent with 1-based arrays indexes ![]() Initialize base cases first for all j and k T = max( T, T,k-i] + val )īest possible value would be max T for all j and k T can be defined in some other way but this definition gives a short formula. let T be the best value out of the first i items and having exactly weight j and volume k.P.s please try providing a solution with bottom up approach to the second question, i am very new to dynamic programming. Plus, what will a state store, it usually stores max value possible till given state in classical knapsack problems, here i guess a state will store total combinations divisible by 8 till that state, but i cant convert this into code. I can't start to think of the second problem, my friend did it by taking three states dp where i and j are just same as first question(the usual ones) while 'k' keeps track of the total items selected, this idea isnt getting in my head. ![]() , this seems alright, but gives me wrong answer.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |