1. Homepage
  2. Programming
  3. COMP3023 Design and Analysis of Algorithms - Programming Assignment: 0-1 Knapsack Problem

COMP3023 Design and Analysis of Algorithms - Programming Assignment: 0-1 Knapsack Problem

Engage in a Conversation
ChinaBNU-HKBU UICCOMP3023Design and Analysis of Algorithms0-1 Knapsack ProblemC++C

COMP3023 23S Programming Assignment CourseNana.COM

Lecture 10 introduces the dynamic programming algorithm for the 0 -1 knapsack problem. In this programming assignment, you need to implement the algorithm under the following requirements. Environment CourseNana.COM

  • The implementation must be done in standard C or C++ (using gcc /g++ compiler). Please do not use visual studio. For the students who do not have the compiler, you can use online GDB at https://www.onlinegdb.com/ .
  • The submissions which cannot pass gcc/g++ compiling, will directly receive 0 . To check whether your code can pass compiling, use online GDB at least. Implementation Structure In your program, you need to implement three source files “ main .c”, “lib.h”, and “lib.c” (“main .cpp” , “lib.h” and “lib.cpp” if you use C++). For “ main .c” (or “main .cpp”)
  • It only contains the “ main ” function.
  • It reads inputs from .txt files . The input txt file is passed to the main function as an argument .
  • Each txt file contains exactly one instance. For “lib.h” and “lib.c” (or “lib.h” and “lib.cpp”)
  • .h is the header file for .c (or .cpp).
  • They contain all other functions except “main”. Functionality
  • The input txt file has 3 lines. The first line has only one integer, the capacity of the bag. The second line has a bunch of positive integers for the value of each item . Two integers are separated by a comma “,”. The third line is in the same format as the second for the weight of each item.
  • When the calculation is finished, print the optimal value and optimal solution(s) one for each line on the screen. (The optimal value is unique, but the optim al solution may not.)
  • Sort the items in the optimal solution(s) in the decreasing order of item indices.
  • The index of items starts from 1. Sample: In the folder “Sample”, you will find all the source files described above. Take t he C version in subfolder “c” for example ( the C++ version is in subfolder “c++” ). Currently, all source files are empty. The main function simple prints the argument on the screen. “lib.c” only tests the linkage. The package also contains “make.bat”. You can open it by a TXT editor. Then, you can see the compilation commands.

After executing “make.bat” (Note t hat .bat files are only executable in Windows), you will have “knapsack.exe”. CourseNana.COM

Suppose the input txt file is named as “in.txt”, we execute “knapsack in.txt”. CourseNana.COM

We see that “in.txt” is printed and “lib.h” and “lib.c” are tested. CourseNana.COM

Example instance Suppo se the input file (in1.txt ) contains 10 3,5,2,6 3,4,2,5 CourseNana.COM

When you finished, t he output should be something like CourseNana.COM

Because 𝑤4+𝑤3+𝑤1=5+2+3=10≤𝑊 𝑣4+𝑣3+𝑣1=6+2+3=11 And 𝑤4+𝑤2=9≤𝑊 𝑣4+𝑣2=11 Submission requirements You need to submit three source files “ main .c”, “lib.h”, and “lib.c” (“ main .cpp” , “lib.h” and “lib.cpp” if you use C++) separately to iSpace . CourseNana.COM

Get in Touch with Our Experts

WeChat (微信) WeChat (微信)
Whatsapp WhatsApp
China代写,BNU-HKBU UIC代写,COMP3023代写,Design and Analysis of Algorithms代写,0-1 Knapsack Problem代写,C++代写,C代写,China代编,BNU-HKBU UIC代编,COMP3023代编,Design and Analysis of Algorithms代编,0-1 Knapsack Problem代编,C++代编,C代编,China代考,BNU-HKBU UIC代考,COMP3023代考,Design and Analysis of Algorithms代考,0-1 Knapsack Problem代考,C++代考,C代考,Chinahelp,BNU-HKBU UIChelp,COMP3023help,Design and Analysis of Algorithmshelp,0-1 Knapsack Problemhelp,C++help,Chelp,China作业代写,BNU-HKBU UIC作业代写,COMP3023作业代写,Design and Analysis of Algorithms作业代写,0-1 Knapsack Problem作业代写,C++作业代写,C作业代写,China编程代写,BNU-HKBU UIC编程代写,COMP3023编程代写,Design and Analysis of Algorithms编程代写,0-1 Knapsack Problem编程代写,C++编程代写,C编程代写,Chinaprogramming help,BNU-HKBU UICprogramming help,COMP3023programming help,Design and Analysis of Algorithmsprogramming help,0-1 Knapsack Problemprogramming help,C++programming help,Cprogramming help,Chinaassignment help,BNU-HKBU UICassignment help,COMP3023assignment help,Design and Analysis of Algorithmsassignment help,0-1 Knapsack Problemassignment help,C++assignment help,Cassignment help,Chinasolution,BNU-HKBU UICsolution,COMP3023solution,Design and Analysis of Algorithmssolution,0-1 Knapsack Problemsolution,C++solution,Csolution,