Home / Expert Answers / Computer Science / write-a-c-c-program-to-solve-the-knapsack-problem-using-one-of-these-different-approaches-implemen-pa691

(Solved): Write a c/c++ program to solve the knapsack problem using one of these different approaches/implemen ...



Write a c/c++ program to solve the knapsack problem using one of these different approaches/implementations: dynamic programming or branch-and-bound. The program is to read a text file named "items.txt" where the first line contains, in order, the number of items and the capacity of the knapsack, followed by a line for each item containing, in order, the weight of the item and the value of the item.  The program is to output the total weight and value of the knapsack along with the list of items selected for the knapsack.Sample input file:
\[
\begin{array}{ll}
8 & 10 \\
2 & 12 \\
4 & 40 \\
3 & 21 \\
7 & 42 \\
1 & 10 \\
5 & 25 \\
3 & 12 \\
2 & 1

Sample input file: \[ \begin{array}{ll} 8 & 10 \\ 2 & 12 \\ 4 & 40 \\ 3 & 21 \\ 7 & 42 \\ 1 & 10 \\ 5 & 25 \\ 3 & 12 \\ 2 & 16 \end{array} \] Sample output: Taken \( (10,87) \) : \( (4,40),(3,21),(1,10),(2,16) \)


We have an Answer from Expert

View Expert Answer

Expert Answer


#include #include #include using namespace std; int main() { ifstream file ("items.txt"); int numItems, capa
We have an Answer from Expert

Buy This Answer $5

Place Order

We Provide Services Across The Globe