Simple c++ problem question
Members - Reputation: 698
Posted 28 April 2013 - 05:33 AM
Alexander Turda - The place where I talk about games, coding, movies, and whatever passes through my mind.
Crossbones+ - Reputation: 2114
Posted 28 April 2013 - 07:06 AM
My guess would be that the aim is to minimize the paper wastage, and to do that in the example case it's not helpful to use the 30x20 sized piece (because that would leave a 22x2=44 sized piece left over, after filling the remaining space with 12x4 pieces).
(12x4x3) + (14x10x3) + (20x8x2) = 884
(42x22)-884 = 40 (the total paper wastage)
Crossbones+ - Reputation: 1408
Posted 28 April 2013 - 05:34 PM
but jumping up to a 15000^2 problem (result 4.7M pieces) takes minutes, I presume because physical memory runs out. I'm kind of itching to try packing the memory. Instead of piece counts and minimum cost, I could memoize only the cost and the index of the "top-level" piece of an optimal configuration for huge memory savings. It shouldn't be hugely expensive to recurse through the configurations at the end to do a final count.
Crossbones+ - Reputation: 6866
Posted 28 April 2013 - 06:18 PM
If I have a rectangle of size 42 x 22 as above.And I want to cut it in pieces of 30 x 20.In the above example,it shows me that the pieces I will get will be 0.How is that possible? Shouldn't it be 1?!
To expand on what Adam_42 said, it sounds like the textbook is asking you to come up with a certain number of cuts of each size such that the minimum amount of paper is wasted.
To give an analogous problem: I have a $3.50. There are 4 things in the store I can buy, all of them costing different prices. Let's say item 1 is $0.50, item 2 is $1, item 3 is $2, and item 4 is $3.25. What should I buy such that I have the least amount of money left? Sure, I could afford to buy one of item #4. But that would leave me with $0.25 remaining, which isn't the "least amount of money left" (because if I instead bought one of items 1, 2, and 3, I would spend $3.50 total and have 0 left, which is more "optimal").
Similarly, in your problem, it's not about "what can you cut?" It's about "what should you cut to get the least waste?"