Answered step by step
Verified Expert Solution
Question
1 Approved Answer
May I know what's wrong with the code? The normal compiler I used give me the correct value of 37, but the hackerearth environment gives
May I know what's wrong with the code? The normal compiler I used give me the correct value of 37, but the hackerearth environment gives me a value of 30.
0/1 Knapsack Given n items, where the im item has the size 5i and the value vi. Put these items into a knapsack of capacity C. Write a function based on the bottom-up dynamic programming technique to calculate the maximum values of the items that fit in the knapsack. Hint: use the following recursive formula as in the lecture: MiiJ) = max {Mil-Mi M(|-1-J-Si) + vii You may need to create and initialize the memory for this question. Sample Input E) IE! Sample output IE 4 Enter the number of items n: 5 Enter the capacity c: 2 l 3 2 Enter the sizes of items (as a list, separate by spacing: 12 la 29 15 Enter the values of items (as a list, separate by spacing: The maximum Value is: 37 Note: Your code must be able to prim the sample output from the provided sample input. However, your code is run against multiple hidden test Cases. Therefore, your code must pass these hidden test cases to solve the problem statement. Limits Time Limit 5.0 sec(s) for each input file Memory Limit: 256 MB Source Limit' 1024 KB Scoring Score is assigned if any testcase passes Allowed Languages C Input 4 5 2132 12162015 Output Enter the number of items n: Enter the capacity C: Enter the sizes of items (as a list, separate by spacing: Enter 'the values of items (as a list, separate by spacing: The maximum Value is: 39 Expected Correct Output Enter the number of items n: Enter the capacity C: Enter the sizes of items (as a list, separate by spacing: Enter the values of items (as a list, separate by spacing: The maximum Value is: 37Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started