The Daily Static
  The Daily Static
UF Archives
Register
UF Membership
Ad Free Site
Postcards
Community

Geekfinder
UFie Gear
Advertise on UF

Forum Rules
& FAQ


Username

Password


Create a New Account

 
 

Back to UserFriendly Strip Comments Index

Dynamic programming by Michiel2005-05-05 12:57:10
  I'm William, and I'll be your assitant for this by williamashbless2005-05-05 15:48:54
    There's a bit of a timezone-difference. :) by Michiel2005-05-06 00:51:41
      Is that algorithm right? by ToLazyToThink 2005-05-06 09:24:48
I'm not 100% certain exactly what your requirements are, so I may be missing something.

My understanding is you start with one board, and you need to cut it into n pieces of different length. The cost of cutting any piece depends on the size of the board (I assume longer boards are more expensive?).

Do I have that right?

So let's look at a simple example.

Let's say it cost:
10ft board - $10
 9ft board -  $9
............
I think you can see the pattern I'm going for.


Let's say:
L1=1ft
L2=6ft
L3=3ft


So we have:
|-|------|---| (L1, L2, L3)


It's easy to see the cheapest way to cut this is at the 7ft mark, and then the 1ft mark. (I'm counting the marks on the original 10ft board).

  1 10ft cut - $10
+ 1  7ft cut - $ 7
------------------
               $17


But if you're allowed to move the pieces around you can do it cheaper.

look at this:
|------|-|---| (L2, L1, L3)


It's easy to see the cheapest way to cut this is at the 6ft mark, and then the 7ft mark.

  1 10ft cut - $10
+ 1  4ft cut - $ 4
------------------
               $14


Did I miss something, I don't think your algorithm caught this case?



I'm afraid I just raised you complexity a bunch, but it's not as bad as it may seem at first. There are lot's of duplicates you can get rid of.

For example:
|------|-|---| (L2, L1, L3)
Is the same as:
|---|-|------| (L3, L1, L2)
It's just the same board flipped.

It's also the same as:
|-|---|------| (L1, L3, L2)
It's just that this time you also flipped the second board before cutting it.

I'm I making sense?

[ Reply ]
        Excelent point, but by Michiel2005-05-06 09:37:55
          I've replied in _today's_ thread. (n/t) by williamashbless2005-05-06 09:46:02

 

[Todays Cartoon Discussion] [News Index]

Come get yer ARS (Account Registration System) Source Code here!
All images, characters, content and text are copyrighted and trademarks of J.D. Frazer except where other ownership applies. Don't do bad things, we have lawyers.
UserFriendly.Org and its operators are not liable for comments or content posted by its visitors, and will cheerfully assist the lawful authorities in hunting down script-kiddies, spammers and other net scum. And if you're really bad, we'll call your mom. (We're not kidding, we've done it before.)