Implement the fractional knapsack problem

Assignment Help Civil Engineering
Reference no: EM132637433

Here, you are required to implement the fractional knapsack problem.

In a fractional knapsack problem, there exists a knapsack of capacity W, set of n items and each item i has a positive benefit bi and a positive weight wi . Your goal is to generate a sample program in a language of your own choice that chooses items with the maximum total benefit but with weight at most W. You are allowed to take fractional amount of an item if you need to do so. You must use a heap-based priority queue in your implementation.

Input: The first line of the input takes n, the number of items. In the next n lines, for each item (from 1 to n), you take the weight and the corresponding benefit. In the last line you take the knapsack capacity W from the user.

Output: In the output, you print out the items (in the increasing order) that has been selected, and for each item how much amount has been taken into consideration and what is the profit made from each item. The last line output the maximum profit that can be made.

Sample Input 5 4 12 8 32 2 40 6 30 1 50 10

Sample Output: Item 2 Amount 1 Profit 4 Item 3 Amount 2 Profit 40 Item 4 Amount 6 Profit 30 Item 5 Amount 1 Profit 50

Total Profit: 124

Reference no: EM132637433

Questions Cloud

What is the gain or loss on constructive bond retirement : What is the gain or loss on constructive bond retirement that should be reported in the 20X3 consolidated income statement
Describe the difference between a chained conditional : Describe the difference between a chained conditional and a nested conditional. Give your own example of each.
Define a structure named moviestar : Define a structure named MovieStar which will have the following elements:
Find the adjustment to income tax expense : The company rate of income tax was reduced from 40% to 35%. Find the adjustment to income tax expense to recognise the impact of the tax rate change
Implement the fractional knapsack problem : Here, you are required to implement the fractional knapsack problem.
Develop an accounting conceptual framework from scratch : If you were to develop an accounting conceptual framework from scratch, where would you start and how would you structure it?
Is the IASB Framework useful in present form : Accounting standards and regulations should aim to state how all situations should be dealt with. Discuss. Is the 2018 IASB Framework useful in its present form
Draw internal architecture of a dram : Draw internal architecture of a DRAM having capacity of 64Mx8 bits, identify its different sections
Analyze the transactions for the month of June : Analyze the following transactions for the month of June in terms of their effect on the basic accounting equation

Reviews

Write a Review

Civil Engineering Questions & Answers

  Determine the magnitude of the forces and acting at c

The tube supports the four parallel forces. Determine the magnitude of the forces and acting at C and D so that the equivalent resultant force of the four forces acts at point O.

  Why is thinning occurring in the walls of the cup

What changes could be made in the operation to correct the problem?

  What type of system would you classify an electric wire

A system consists of a gas confined between a cylinder and piston such that work and heat may cross the boundary. What type of system is that? What type of system is a free body as used in mechanics or civil engineering? What type of system would you..

  What is the bod concentration at the outflow of the pond

A pond is used to treat a dilute municipal waste-water before the liquid is discharged into a river. The inflow to the pond has a flow rate of Q = 4,000 m3/day and a BOD concentration of Cin = 25 mg/L.

  How will the specific humidity change

the relative humidity of the air contained in a well-sealed room change as it is heated?

  What is the minimum settling velocity required for particle

Assume that this or another settling chamber removes all particles having settling velocities greater or equal to 0.04 cm s-1. What is the min-imum particle diameter that would be entirely removed by such a settling chamber? Express your answer in ..

  What velocity will the officer observe

Car A is moving with constant speed v on the straight and level highway

  Describe environmentally sustainable transit system

Literature review on the City of Toronto & Toronto's public transit system - Describe environmentally sustainable transit, a common measure of environmental

  What is the dry unit weight, the saturated unit weight

What is the dry unit weight, the saturated unit weight, and the buoyant unit weight, of a soil having a void ratio of 0.5 and a value of Gs of 2.7?

  Compare the stress in each rod

Use the same numerical values for the tensile load in each rod and the rod's diameter, and compare the stress in each rod.

  Determine the rate of increase of the piezometric head

The gasoline at point C and time t has an acceleration given by a=(-12i+40k) ft/s^2 where i and k are the horizontal and vertical unit vectors. Find the rate of increase of the piezometric head and the pressure in the x,y,z and a directions.

  What is the elevation of point b

You must establish the elevation of point B from point A (elevation 216.612 m). A and B are on opposite sides of a 12 lane highway. Reciprocal leveling is used with the following results: Station BS HI FS Elevation BM 130 0.702 188.567

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd