Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Algorithms
  4. Optimization problem with sets

Optimization problem with sets

Scheduled Pinned Locked Moved Algorithms
algorithmsperformancehelptutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    paradoxonok
    wrote on last edited by
    #1

    Hello! I have a set that contains maximum 10^6 items. All item are 4^n number, where 0 <= n <= 11, all items have a price that can be 1 <= price <= 10^8. And I also have another number k, where k is 4^n number and 0 <= n <= 11. The items are ordered monotonically first according to size of numbers, then to prices. I want to take the sum of the items that equal to number k, and the price is minimal. The example: A := {16(1),16(2),16(3),16(4),64(11)}and k=64. (format: Number (price) -> 16(1)) So, the solution is 16(1),16(2),16(3),16(4), because 1+2+3+4=10 smaller then 11. Any idea? Thanks!

    A P N 3 Replies Last reply
    0
    • P paradoxonok

      Hello! I have a set that contains maximum 10^6 items. All item are 4^n number, where 0 <= n <= 11, all items have a price that can be 1 <= price <= 10^8. And I also have another number k, where k is 4^n number and 0 <= n <= 11. The items are ordered monotonically first according to size of numbers, then to prices. I want to take the sum of the items that equal to number k, and the price is minimal. The example: A := {16(1),16(2),16(3),16(4),64(11)}and k=64. (format: Number (price) -> 16(1)) So, the solution is 16(1),16(2),16(3),16(4), because 1+2+3+4=10 smaller then 11. Any idea? Thanks!

      A Offline
      A Offline
      Alan Balkany
      wrote on last edited by
      #2

      The problem and your notation aren't clear.

      1 Reply Last reply
      0
      • P paradoxonok

        Hello! I have a set that contains maximum 10^6 items. All item are 4^n number, where 0 <= n <= 11, all items have a price that can be 1 <= price <= 10^8. And I also have another number k, where k is 4^n number and 0 <= n <= 11. The items are ordered monotonically first according to size of numbers, then to prices. I want to take the sum of the items that equal to number k, and the price is minimal. The example: A := {16(1),16(2),16(3),16(4),64(11)}and k=64. (format: Number (price) -> 16(1)) So, the solution is 16(1),16(2),16(3),16(4), because 1+2+3+4=10 smaller then 11. Any idea? Thanks!

        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #3

        This sounds like a homework problem, and if so, you should consult with your instructor. As the other poster had said, your problem is not entirely clear, may want to rephrase it.

        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

        1 Reply Last reply
        0
        • P paradoxonok

          Hello! I have a set that contains maximum 10^6 items. All item are 4^n number, where 0 <= n <= 11, all items have a price that can be 1 <= price <= 10^8. And I also have another number k, where k is 4^n number and 0 <= n <= 11. The items are ordered monotonically first according to size of numbers, then to prices. I want to take the sum of the items that equal to number k, and the price is minimal. The example: A := {16(1),16(2),16(3),16(4),64(11)}and k=64. (format: Number (price) -> 16(1)) So, the solution is 16(1),16(2),16(3),16(4), because 1+2+3+4=10 smaller then 11. Any idea? Thanks!

          N Offline
          N Offline
          novice__geek
          wrote on last edited by
          #4

          Your problem sounds like the knapsack problem. 4^n just acts as item-id (given in this peculiar notation to confuse) while k is the capacity of the knapsack. Its easy to solve this problem using the method of dynamic programming. Brute-force approaches which rely on generating combination also exist.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups