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

  Engineering ethics and ethical issue

what is the engineering ethics course where to write about any engineering ethical case and discuss the ethical issue?

  Engineering ethics and concept and cases

what is the engineering ethics case related to civil engineering with reference and discuss all the engineering ethics issues which covered the "Engineering etics concepte and cases?

  Transportation and management

In the construction management, there is a lot of procurement route that are necessary and suitable for the construction industry.

  Supporting Investment Promotion: ERNST & YOUNG

Ernst & young is currently providing support to various sectors. In this regards it was felt that if this report is able to document good practices currently being adopted or planned in ceramic sector.

  Personalized Cancer Therapy-A step forward

Cancer is the uncontrolled growth of abnormal cells in the body resulting in tumours that can be benign or malignant (cancerous cells). A proper treatment is necessary to fight with this serious disease.

  Discuss the different environmental companies

Discuss the different agencies, institutes, centers, different environmental companies that are active in UAE.

  Develop a simple urban constructed wetland design

Develop a simple urban constructed wetland design.

  Evaluate company performance in relation to GRI standards

Evaluate company performance in relation to GRI standards and comment on Stigler's theory.

  Water system design

Determine the corresponding error in the computed discharge

  Hydraulic behaviour in open channel

Describe how test flumes and associated equipment are used to assess and confirm hydraulic behaviour in open channel

  Write a paper on steel sustainability

Write a paper on steel sustainability.

  Writing case study about bridge collapse

Writing case study about bridge collapse

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