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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 04:00, terrell31
Write a method that takes in an array of point2d objects, and then analyzes the dataset to find points that are close together. be sure to review the point2d api. in your method, if the distance between any pair of points is less than 10, display the distance and the (x, y)s of each point. for example, "the distance between (3,5) and (8,9) is 6.40312." the complete api for the point2d adt may be viewed at ~pf/sedgewick-wayne/algs4/documenta tion/point2d. html (links to an external site.)links to an external site.. try to write your program directly from the api - do not review the adt's source code.
Answers: 1
image
Computers and Technology, 24.06.2019 17:00, kappy10
Anew author is in the process of negotiating a contract for a new romance novel. the publisher is offering three options. in the first option, the author is paid $5,000 upon delivery of the final manuscript and $20,000 when the novel is published. in the second option, the author is paid 12.5% of the net price of the novel for each copy of the novel sold. in the third option, the author is paid 10% of the net price for the first 4,000 copies sold, and 14% of the net price for the copies sold over 4,000. the author has some idea about the number of copies that will be sold and would like to have an estimate of the royal- ties generated under each option. write a program that prompts the author to enter the net price of each copy of the novel and the estimated number of copies that will be sold. the program then outputs he royalties under each option and the best option the author could choose. (use appropriate named constants to store the special values such as royalty rates and fixed royalties.
Answers: 1
image
Computers and Technology, 25.06.2019 07:50, demilasyone01
In addition to the four primary computer operations, today's computers typically also perform functions.
Answers: 1
image
Computers and Technology, 25.06.2019 08:00, groverparham3
The heart of a computer. basic input/output systemselectmain memoryserial portcentral processing unit (cpu)
Answers: 3
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 in other subjects:

Konu
Mathematics, 09.02.2021 21:30
Konu
Chemistry, 09.02.2021 21:30
Konu
Mathematics, 09.02.2021 21:30