Question: In java and explain please For the homework, your program should read the weight and value of each item from a user and determine the

In java and explain please For the homework, your program should readIn java and explain please

For the homework, your program should read the weight and value of each item from a user and determine the best subset. In the homework, you can assume that the number of items is less than 15. Also, you should assume that each item has only one. Input format: This is a sample input from a user. 2 5 3 12 4 10 The first line (= 2 in the example) is the number of items for the knapsack problem. The second line (=5 in the example) is the knapsack capacity. After that, the two following lines indicate the capacity and value of each item. For instance, the third line = 3 12) indicates that the first item's capacity is 3 and its value is 12. The last line (= 4 10) indicates that the second item's capacity is 4 and its value is 10. Sample Run 0: Assume that the user typed the following lines Sample Run 1: Assume that the user typed the following lines 2 5 3 12 4 10 3 5 2 12 1 10 3 20 This is the correct output of your program. Item: 1 Capacity: 3 Value: 12 This is the correct output of your program. Item: 1 3 Capacity: 5 Value:32 Sample Run 3: Assume that the user typed the following lines Sample Run 2: Assume that the user typed the following lines 2 10 24 26 4 5 2 30 3 40 2 30 3 40 This is the correct output of your program. Item:1 2 Capacity:4 Value: 10 This is the correct output of your program. Item: Multiple solutions Capacity:5 Value: 70 Sample Run 4: Assume that the user typed the following lines 2 10 28 9 6 This is the correct output of your program. Item: 1 Capacity: 2 Value: 8 For the homework, your program should read the weight and value of each item from a user and determine the best subset. In the homework, you can assume that the number of items is less than 15. Also, you should assume that each item has only one. Input format: This is a sample input from a user. 2 5 3 12 4 10 The first line (= 2 in the example) is the number of items for the knapsack problem. The second line (=5 in the example) is the knapsack capacity. After that, the two following lines indicate the capacity and value of each item. For instance, the third line = 3 12) indicates that the first item's capacity is 3 and its value is 12. The last line (= 4 10) indicates that the second item's capacity is 4 and its value is 10. Sample Run 0: Assume that the user typed the following lines Sample Run 1: Assume that the user typed the following lines 2 5 3 12 4 10 3 5 2 12 1 10 3 20 This is the correct output of your program. Item: 1 Capacity: 3 Value: 12 This is the correct output of your program. Item: 1 3 Capacity: 5 Value:32 Sample Run 3: Assume that the user typed the following lines Sample Run 2: Assume that the user typed the following lines 2 10 24 26 4 5 2 30 3 40 2 30 3 40 This is the correct output of your program. Item:1 2 Capacity:4 Value: 10 This is the correct output of your program. Item: Multiple solutions Capacity:5 Value: 70 Sample Run 4: Assume that the user typed the following lines 2 10 28 9 6 This is the correct output of your program. Item: 1 Capacity: 2 Value: 8

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!