Question: Write a code using Dynamic Programming to solve the Knapsack problem. The code should perform these tasks: 1. Read input.txt file providing the inputs in
Write a code using Dynamic Programming to solve the Knapsack problem. The code should perform these tasks:
1. Read input.txt file providing the inputs in the following format:
N K
w0 v0
w1 v1
wn-1 vn-1
The first row contains the number of items N and capacity of the knapsack K. Each of the ollowing N rows contain the weight and value of an item.
2. Construct a table using dynamic programming approach (as studied in class).
3. Write a code to generate the solution.txt file in the followng format:
W V
0/1 0/1 0/1 . 0/1
The first row contains the total weight W and value V of the knapsack after picking the items. The scond row contains N values consisting of 0s and 1s corresponding to each item, 0 if the item is not picked and 1 if it is picked.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
