|
1 | 1 | # Instructions
|
2 | 2 |
|
3 |
| -In this exercise, let's try to solve a classic problem. |
| 3 | +Your task is to determine which items to take so that the total value of his selection is maximized, taking into account the knapsack's carrying capacity. |
4 | 4 |
|
5 |
| -Bob is a thief. |
6 |
| -After months of careful planning, he finally manages to crack the security systems of a high-class apartment. |
7 |
| - |
8 |
| -In front of him are many items, each with a value (v) and weight (w). |
9 |
| -Bob, of course, wants to maximize the total value he can get; he would gladly take all of the items if he could. |
10 |
| -However, to his horror, he realizes that the knapsack he carries with him can only hold so much weight (W). |
11 |
| - |
12 |
| -Given a knapsack with a specific carrying capacity (W), help Bob determine the maximum value he can get from the items in the house. |
13 |
| -Note that Bob can take only one of each item. |
14 |
| - |
15 |
| -All values given will be strictly positive. |
16 | 5 | Items will be represented as a list of items.
|
17 | 6 | Each item will have a weight and value.
|
| 7 | +All values given will be strictly positive. |
| 8 | +Bob can take only one of each item. |
18 | 9 |
|
19 | 10 | For example:
|
20 | 11 |
|
21 |
| -```none |
| 12 | +```text |
22 | 13 | Items: [
|
23 | 14 | { "weight": 5, "value": 10 },
|
24 | 15 | { "weight": 4, "value": 40 },
|
25 | 16 | { "weight": 6, "value": 30 },
|
26 | 17 | { "weight": 4, "value": 50 }
|
27 | 18 | ]
|
28 | 19 |
|
29 |
| -Knapsack Limit: 10 |
| 20 | +Knapsack Maximum Weight: 10 |
30 | 21 | ```
|
31 | 22 |
|
32 | 23 | For the above, the first item has weight 5 and value 10, the second item has weight 4 and value 40, and so on.
|
33 |
| - |
34 | 24 | In this example, Bob should take the second and fourth item to maximize his value, which, in this case, is 90.
|
35 | 25 | He cannot get more than 90 as his knapsack has a weight limit of 10.
|
0 commit comments