CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2011

    Unhappy Knapsack problem using backtracking

    I have to write a program that has a given knapsack weight limit and put items in it with the maximum weight, items doesn't have value only weight.
    i.e Knapsack weight limit: 17
    items weights : 3, 8, 4, 1, 5, 13
    I have to put in it items with the higest weight in this case would be 13 + 4, of course all items will be sorted from the highest one to the lowest one, that I already have.
    Can anyone help, Ive been looking on Web for that but I only found examples that have items values and weights.

  2. #2
    Join Date
    Jun 2009

    Re: Knapsack problem using backtracking

    What if you were to say that all your item values are 1, wouldn't the algorithms you found on internet still work?
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.