Cryptology - Unofficial St. Mary's College of California Web Site
Cryptology - Unofficial St. Mary's College of California Web Site
Cryptology - Unofficial St. Mary's College of California Web Site
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
220 CHAPTER 11. KNAPSACK CIPHERS<br />
Example: There are 8 piles <strong>of</strong> gold bars. Every bar in a given pile weighs<br />
the same. Each in pile 1 weighs 18oz. In pile 2 each weighs 29oz. Pile 3: 34oz,<br />
Pile 4: 41oz, Pile 5: 67oz, Pile 6: 88oz, Pile 7: 101oz and Pile 8: 119oz. Your<br />
backpack can carry a maximum <strong>of</strong> 300 oz (about 19 lbs). Which bars and how<br />
many should you pick 1<br />
⋄<br />
11.2 A Related Knapsack Problem<br />
An apparent simplification is to assume the cave contains exactly one bar <strong>of</strong><br />
any particular weight. So you only need to decide “yes” or “no” to each bar,<br />
rather than deciding how many bars from each pile to take. We also modify the<br />
problem to demand an exact amount <strong>of</strong> gold.<br />
Examples:<br />
(1) The weights <strong>of</strong> the bars are 4, 7, 12, 19, 22, and 25 lbs. If the total amount<br />
demanded is 55 lbs., this weight can be supplied: 4 + 7 + 19 + 25 = 55.<br />
However, there is no way to choose bars <strong>of</strong> total weight exactly 50 pounds.<br />
(2) The weights <strong>of</strong> the bars are 27, 31, 41, 48, 55, 59, 62, 65, 73, and 77. Total<br />
amount wanted is 257. Is this weight possible What about 364 2<br />
⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄ ⋄<br />
This problem may seem easier than the first, but it is still quite hard. Why<br />
Think <strong>of</strong> the number <strong>of</strong> possibilities that must be considered. For each bar we<br />
must decide whether we want it or not:<br />
For one weight, say 27 lbs.: Do we want it yes or no (2 = 2 1 choices).<br />
For 27 and 31: yes/no and yes/no, or yy, yn, ny or nn (4 = 2 2 choices).<br />
For 27, 31, and 41: y/n and y/n and y/n gives yyy, yyn, yny, nyy, ynn,<br />
nyn, nny, and nnn (8 = 2 3 choices).<br />
By the time we have 5 weights we must make 2 5 = 32 choices, 8 weights demand<br />
2 8 = 256, and 10 weights, as in the last example, leads to 2 10 = 1024<br />
possibilities, too many for a quick answer if checking by hand. In fact, if there<br />
were 100 bars to choose from (a moderately rich dragon, in other words), there<br />
would be<br />
2 100 ≈ 1, 000, 000, 000, 000, 000, 000, 000, 000, 000, 000<br />
1 I can make 295 as 2 × 18 + 2 × 34 + 3 × 41 + 67. Can you do better<br />
2 255 is possible (in seven different ways!) but 364 is not.