Computers and Technology

Given n items with weights w1, w2, and wn, and a bag with a weight capacity of w, the problem of finding the items with the maximum total weight to store in the bag is called the 0/1 knapsack problem. Let m(i, w) denote the total weight of the best solution of placing the first i items into a bag with weight capacity w. The problem can be solved using the following recursion: m(0, weightLimit) 0; m(i, w)m(i-1, weightLimit) if wi> weightLimit Write a recursive method for computing m(i, w) using following method header: public static double m(int i, double weightimit, doublell w) where w is an array of the weights for items. Write a test program that prompts the user to enter the number of the items and weight for each item and the weight capacity of the bag, and displays the maximum total weight of the items that can be placed in the bag. Your output should look like that below:
Enter the number of items:6
Enter the weights for each item: 2 38495
Enter the weight limit for the bag: 7
The maximum weight of the items placed in the bag is 7.0

answer
Answers: 2

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 00:30, Thisisdifinite
Which of the following would you find on a network
Answers: 3
image
Computers and Technology, 23.06.2019 02:30, chaaaa
People with high self-esteem: accept their strengths and weaknesses. believe that failed experiences are failures of their whole self. feel good about who they are only when they reach total success. need positive external experiences to counteract negative feelings that constantly plague them.
Answers: 1
image
Computers and Technology, 23.06.2019 07:10, anika420
If you want to import a picture into a dtp application, what must you do first? draw an image frame. import text. open the folder containing the file. select get image… from the windows menu.
Answers: 2
image
Computers and Technology, 24.06.2019 13:30, yola32
What is the most important for you to choose before you build a network?
Answers: 1
Do you know the correct answer?
Given n items with weights w1, w2, and wn, and a bag with a weight capacity of w, the problem of fin...

Questions in other subjects:

Konu
Law, 07.02.2021 16:20
Konu
Biology, 07.02.2021 16:20
Konu
Computers and Technology, 07.02.2021 16:30