![]() ![]() So what is left? First of all, it is some solution for a knapsack of total weight, capital W- wn, and it also uses only items from 1 to n- 1, because, well, we just took out the nth item, right? If, on the other hand, the initial optimal solution for the knapsack of total weight W does not contain the nth item, well, then it contains only items from 1 to n minus 1. I assume that it contains, and let's again take this nth item out of our current solution. It is not difficult to see that there are only two cases, either it contains the lost item, or it doesn't contain it. So still, let's take a closer look at our optimal solution. So this is why we need to come up with a different notion of a subproblem. This means that we cannot add another copy of the nth element to it, right, because then the resulting solution will contain two copies of the nth element which is now forbidden by the problem formulation. I assume however, that the optimal solution for the smaller knapsack, already contains the nth item. So if we take we the smaller solution and we add the nth item to it, we get an optimal solution for the initial knapsack of total weight, W. So we argue, well similarly to the previous case that if we take this item out of the current knapsack, then what we get must be an optimal solution for a knapsack of smaller weight, namely of total weight W- wn. And assume for the moment that we know that it contains the nth element. ![]() So once again, let's consider an optimal subset of items for a knapsack of total weight capital W. Still it is important to understand where our algorithms, where our reasoning more generally fails for this problem. So this means that if we just run our previous algorithm, it will produce an incorrect result. Well this is simply because in our toy example is that optimal value for the Knapsack with repetitions was 48 while the optimal value for the Knapsack without repetitions was 46. Well, we already know that our previous same reason cannot produce the right answer for our new very namely for the Knapsack without repetitions problems. So this is also to remind you the formal statement of the problem, so we emphasize once again that we are not allowed to take more than a single copy of each item. Recall that in this problem we're give a single copy of each item. In this video we will be designing a dynamic formatting solution for the Knapsack without Repetitions problem. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |