A well-known problem in computer science is called the knapsack problem. A variation is as follows: Given a collection of weights of (possibly) different integral values, is it possible to place some of the weights in a knapsack so as to fill it to some exact total weight? For example, if the weights are 3, 5, 6, and 9, then it is possible for such totals as 3, 8, 11, 14, 17, etc. to be made exactly, but 2, 4, 22, etc. are not possible. Create a Knapsack application that solves this problem. Save & Run Load History Show CodeLens 1 public class Knapsack{ 2 3 /* Returns true if there exists a subset of the items in 4 * weights[start..weights.length] that sum to goal. pre: items in weights[start..weights.length] > 0 post: true has been returned if there exists a subset 7 * of items in weights[start..weights.length] that sum to goal. 8 */ public boolean fillKnapsack (int[] weights, int goal, int start) 10 11 } 12 } 13 LO
A well-known problem in computer science is called the knapsack problem. A variation is as follows: Given a collection of weights of (possibly) different integral values, is it possible to place some of the weights in a knapsack so as to fill it to some exact total weight? For example, if the weights are 3, 5, 6, and 9, then it is possible for such totals as 3, 8, 11, 14, 17, etc. to be made exactly, but 2, 4, 22, etc. are not possible. Create a Knapsack application that solves this problem. Save & Run Load History Show CodeLens 1 public class Knapsack{ 2 3 /* Returns true if there exists a subset of the items in 4 * weights[start..weights.length] that sum to goal. pre: items in weights[start..weights.length] > 0 post: true has been returned if there exists a subset 7 * of items in weights[start..weights.length] that sum to goal. 8 */ public boolean fillKnapsack (int[] weights, int goal, int start) 10 11 } 12 } 13 LO
C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter15: Recursion
Section: Chapter Questions
Problem 18SA
Related questions
Question
use Java thank you
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning