Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CPS 3 4 0 - Lab 3 ( 2 0 pts ) Due: Thursday, Jan. 2 5 , 2 0 2 4 , at 1

CPS 340- Lab 3(20pts)
Due: Thursday, Jan. 25,2024, at 11:59pm via Blackboard
In this lab, you are tasked with implementing an exhaustive search algorithm to solve the 0-1 knapsack problem. As you recall (Chapter 3 in the textbook), in the 0-1 knapsack problem items cannot be broken up so must either all be placed in the knapsack or left out) the objective is to maximize the total value of the items placed in the knapsack, constrained by the total weight capacity of the knapsack.
Input
The first line contains an integer n, representing the number of items available to lace in the knapsack. The second line contains an integer W, representing the total weight capacity of the knapsack. The third line contains n integers, separated by spaces. These integers represent the weight of each item. The fourth line contains n integers, separated by spaces. These integers represent the value of each item.
Output
The output contains 1 line only, with 1 integer. The integer represents the total value of the items placed in the knapsack.
Sample Test Cases
Input
4
5
2132
12102017
39
5
6
32145
2520154050
65
Output
132
39
6
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions