Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Imagine you are a treasure hunter and given a knapsack that can hold a certain weight capacity. You will be exploring a far - away
Imagine you are a treasure hunter and given a knapsack that can hold a certain weight capacity. You will
be exploring a faraway land for long lost gold bars. The gold bars will be of varying weight. You cannot
take more gold bars than your knapsack can hold, but you obviously want to take as much gold as
possible. You also cannot take fractions of the gold bars.
Write a program such that it will receive as inputs an array of gold bar weights and a knapsack
capacity, and it will output the maximum sum weight of the gold bars that can be taken.
The unit of weight is irrelevant you can assume they are all kilogram or pounds, it doesnt matter In
addition, the weight and capacity will always be an integer.
For example, if the array of gold bar weights is and the knapsack capacity is then you can
take a maximum of units of weight of gold. The weights of gold bars taken in this example is and
If there are not any gold bars that can be taken, your program should return
You cannot import any library in your code. Your code must have a function called maxgold and that
will take in two inputs: the array of gold weights and the knapsack capacity.
Step 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