Question: You are given an array, weights, that contains the weights of some cargo items in pounds. You want to load a truck with items from

 You are given an array, weights, that contains the weights of

You are given an array, weights, that contains the weights of some cargo items in pounds. You want to load a truck with items from the list up to its capacity. The truck has a maximum capacity of 1,000 pounds. For this problem use a "dumb" algorithm. That is, start with the first item in the list and go through the items in order. loading each one if there is enough remaining capacity on the truck For example, if the weights were [ 400, 250, 700, 60, 300), you would load the 400-pound item, then the 250-pound item, then the 60- pound item, for a total of 710 pounds of cargo. This method does not find the best solution - we will improve on it in subsequent problems. The weights will be generated randomly, so you cannot hard-code the answer - you must write a general algorithm to do it Once the loading is complete, print a message indicating how many pounds of cargo were loaded onto the truck. NOTE. To satisfy the auto-grader, update the variable capacity so that it contains the remaining capacity of the truck. For example, if 943 pounds of cargo are loaded, capacity should be 57 Script Reset D MATLAB Documentation 1 %The weights of the cargo items are generated at random 4 weights - randi(500, 1, randi (10)) 7 capacity - 1800; %cargo capacity of the truck

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!