subject

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

ansver
Answers: 2

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 12:10
Linux is distributed under gnu gpl. why is this important? a. it ensures that only torvalds can profit from the sale of linux b. it prevents unknowledgeable users from downloading programs they don't know how to operate. c. it provides protection for the developers who created linux. d. it states that anyone can copy, modify, and share the program if changes are made public.
Answers: 1
question
Computers and Technology, 22.06.2019 18:30
List the five on-board vehicle subsystems
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
Jason needs to learn a new web tool. he went through his books to understand more about it. now he wants hands-on experience with using that tool. what would him? jason can use websites where workspace is provided to test the results of your code.
Answers: 2
question
Computers and Technology, 23.06.2019 06:30
On early television stations, what typically filled the screen from around 11pm until 6am? test dummies test patterns tests testing colors
Answers: 1
You know the right answer?
Given n items with weights w1, w2, and wn, and a bag with a weight capacity of w, the problem of fin...
Questions
question
Mathematics, 02.03.2021 14:20
question
History, 02.03.2021 14:20
question
Physics, 02.03.2021 14:20
question
World Languages, 02.03.2021 14:20
question
Physics, 02.03.2021 14:20
question
Physics, 02.03.2021 14:20
question
Mathematics, 02.03.2021 14:30
question
Chemistry, 02.03.2021 14:30
Questions on the website: 13722363