CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Deploying Windows Server 2008 with System Center
  • Remote Desktop Protocol Performance Improvements in Windows Server 2008 R2 and Windows 7
  • The Microsoft Dynamics CRM Security Model
  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > General Discussion > Algorithms & Data Structures
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Algorithms & Data Structures Discuss algorithms & data structures. Topics are not specific to any programming language.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old October 2nd, 2009, 11:06 AM
    paradoxon paradoxon is offline
    Junior Member
     
    Join Date: Oct 2009
    Posts: 1
    paradoxon is an unknown quantity at this point (<10)
    Optimal algorithm for a splitting problem

    Hello everybody!

    My problem is this:

    I have a unit and lot of parts. All parts have a price. These parts create a unit, but lot of way can be exist to create a unit.

    All numbers are power of 4, except the price, because it can be optional. The minimum value is 4^0 and the maximum is 4^11.

    For example:

    The unit is 1024, and the parts are:

    256 10
    256 20
    256 30
    256 40
    1024 98
    1024 513

    So, I can make a unit if I will add 256+256+256+256, and I have to pay for that 100. Or I will chose only 1024 and I have to pay for that 98. 98 is smaller than 100, so this will be an optimal solution.

    Which algorithm does it solve this problem optimal, if the prices are incremental ordered and the units are ordered too, like in the example.

    Be on the safe side, I show you an another example.

    The unit is 256, and the parts are:

    16 1
    16 1
    16 3
    16 4
    64 1
    64 1
    64 2
    256 14

    The optimal solution is 16+16+16+16+64+64+64, because 1+1+3+4+1+1+2=13, and 256 is 14.

    Thank you!
    Reply With Quote
      #2    
    Old October 4th, 2009, 10:53 AM
    jim enright jim enright is offline
    Member
     
    Join Date: Oct 1999
    Location: ks
    Posts: 486
    jim enright will become famous soon enough (50+)
    Re: Optimal algorithm for a splitting problem

    if i understand the problem correctly what you need to do is set up an exhaustive set of possibilities and simply use a "champion - challenger" approach to finding the least cost solution.

    solution list:

    parts: 1 4 16 64 256
    0 0 0 0 1
    0 0 0 4 0
    0 0 4 3 0
    0 0 8 2 0
    ...

    256 0 0 0 0

    these solutions need to have total prices computed.

    this was set up for 256 as unit - you need to set up for 1024.

    presumably this is an excercise to set up loops or recursive processes to generate the next solution.

    Last edited by jim enright; October 4th, 2009 at 10:54 AM. Reason: mistake
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > General Discussion > Algorithms & Data Structures


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:41 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.