DP - knapsack problem

insert image description here

When we talk about the backpack problem, it can be imagined that a child is going to travel, but he can only bring a backpack with limited capacity. He has a number of items he can choose to put in his backpack, each with its own weight and value. The goal of the children is to choose items to maximize the total value without exceeding the capacity of the backpack.

01 backpack problem

at 01 0101 In the backpack problem, children can only choose to put each item in the backpack completely or not put it in the backpack at all. Each item has its own weight and value, and backpacks have a fixed capacity limit. The child's goal is to choose items that maximize their total value while not exceeding the capacity limit of the backpack.

For example, the child's backpack capacity is 10 1010 , he has the following items to choose from:

Item AAA : Weight3 33 , value4 44
itemsBBB : Weight4 44 , value5 55
itemCCC : Weight2 22 , value3 33

In this case, the child can select all items and their total weight is 9 99 , the total value is12 1212 , while not exceeding the capacity limit of the backpack.

fractional knapsack problem

In the fractional knapsack problem, children can choose a portion of each item to put in a knapsack. Each item has its own weight and value, and backpacks have a fixed capacity limit. The child's goal is to select parts of the items that maximize their total value while not exceeding the capacity limit of the backpack.

For example, the child's backpack capacity is 10, and he has the following items to choose from:

Item A: Weight 3, Value 4
Item B: Weight 10, Value 6
Item C: Weight 2, Value 3

In this case, the child can choose item AAAll of A , part of item B (with a weight of5 55 ), and itemsCCAll of C. so the total weight is10 1010 , the total value is4 + ( 5 / 10 ) ∗ 6 + 3 = 10 4 + (5/10)*6 + 3 = 104+(5/10)6+3=10 while not exceeding the capacity limit of the backpack.

multiple knapsack problem

In the multiple knapsack problem, each item has its own weight, value, and available quantity. Backpacks have a fixed capacity limit. The child's goal is to choose the number of items that maximizes their total value while not exceeding the capacity limit of the backpack and the available number of items.

For example, the child's backpack capacity is 10, and he has the following items to choose from:

Item A: Weight 3, Value 4, Quantity 2 Available
Item B: Weight 4, Value 5, Quantity 1 Available
Item C: Weight 2, Value 3, Quantity 3 Available

In this case, the child can choose two items A and two items C. In this way, the total weight is (3 2) + (2 2) = 10, and the total value is (4*2) + (3 *2) =14, while not exceeding the capacity limit of the backpack and the available quantity limit of items.

complete knapsack problem

In the unbounded knapsack problem, each item has its own weight and value, but the number of each item is infinite. Backpacks have a fixed capacity limit. The child's goal is to choose the number of items that maximizes their total value while not exceeding the capacity limit of the backpack.

For example, the child's backpack capacity is 10, and he has the following items to choose from:

Item A: Weight 3, Value 4
Item B: Weight 4, Value 5
Item C: Weight 2, Value 3

In this case, the child can choose item C five. So the total weight is 5*2) = 14, and the total value is 3*5 = 15, while not exceeding the capacity limit of the backpack.

Guess you like

Origin blog.csdn.net/DUXS11/article/details/132295005