IITKESO207SPA3B - Knapsack Problem
This problem deals with the simple knapsack problem.
You are required to find the set of of items that goes into the knapsack for which the value is maximized. The input will contain the number of items, value, space taken up by each item, and the total capacity of the knapsack.
The input will contain three lines. The first line will an integer n, which is the number of items you have to consider. The second line will contain n pairs of space, value each indicating how much it costs to put the item inside the knapsack, and how much value it has for the knapsack. The third line will contain a single integer, C that is the total capacity of the knapsack.
You are required to print m space seperated integers, which are in non decreasing order, of the item costs that will be put in the knapsack for maximum value. (The costs must add up to be less than or equal to the knapsack capacity).
10 2 3 4 3 8 3 2 3 4 3 10 3 12 3 7 3 9 3 15 3 19
2 2 4 4 7
Please note that apart from the sample test case posted here, there will be other hidden test cases that your code will checked on. The final score you see is a percentage of the test cases you have passed. If you pass only the sample test case, you will get 0/100 (even though your score will be shown as 10/100).
Each of these questions are finally worth the points mentioned in the assignment pdf file. So your credit for this problem shall be your score/100 * points for this question. Your final credit for programming assignment 3 shall be final score / 55 * 100.
Plagiarism and copying
Strict action will be taken against students who are found to be indulging in plagiarism. Please note that changing variable names, removing indentation or moving code around will not help with regards to plagiarism checking.
Last edit: 2017-06-30 00:59:49
In knapsack, we consider items one by one. So, in case there are multiple solutions, print that solution which you discovered first (in this case 2 4).Last edit: 2017-06-29 21:30:48
A sample test case would be helpful
The question asks to print in non decreasing order; 2 2 2 and 2 4 are two possible solutions with volume equal to 12.
What should I print for the following case: