Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

in C# please not C++ Write a program to solve the Knapsack problem using backtracking algorithm. Your code should contain a method called Knapsack, the

image text in transcribed

in C# please not C++

Write a program to solve the Knapsack problem using backtracking algorithm. Your code should contain a method called Knapsack, the method takes two parameters, the first is a 2xN array of integers that represents the items and their weight and value and the second is an integer that represents the maximum weight of the knapsack. Assume that the initial state is an empty Knapsack, and the actions are putting objects in the Knapsack and if the weight of selected items exceeds the total weight then you have to backtrack. Your method should print (on the screen) three lines: The first one represent the chosen items(indices), the second line gives the total weight of the selected items and the last one represent the total value of the selected items. An example: weight 7 3 9 12 10 value 4 3 4 7 8 Note: total weight 20 The Answer should be written in C# Output: 0 1 4 20 15 Your code should run in real time. (Hint: the order in which you select the actions will affect the run time)

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

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions