Skip to content
Official PYQ · 2014

GATE CS 2014 Set 1 Q37 — Algorithm Design: Greedy Techniques

Explain with AI
There are 55 bags labeled 11 to 55. All the coins in a given bag have the same weight. Some bags have coins of weight 1010 gm, others have coins of weight 1111 gm. I pick 1,2,4,8,161, 2, 4, 8, 16 coins respectively from bags 11 to 55 Their total weight comes out to 323323 gm. Then the product of the labels of the bags having 1111 gm coins is ___.
View worked solution

Answer: 12

Let xi∈{0,1}x_i \in \{0, 1\} represent whether bag ii contains 1111 gm coins (xi=1x_i = 1) or 1010 gm coins (xi=0x_i = 0) for i∈{1,2,3,4,5}i \in \{1, 2, 3, 4, 5\}.

The number of coins picked from bags 1,2,3,4,1, 2, 3, 4, and 55 are 1,2,4,8,1, 2, 4, 8, and 1616 respectively. The total number of coins picked is:

1+2+4+8+16=31 coins1 + 2 + 4 + 8 + 16 = 31 \text{ coins}

If all bags contained 1010 gm coins, the total weight would be:

31×10=310 gm31 \times 10 = 310 \text{ gm}

The actual total weight is 323323 gm. The excess weight is due to the bags containing 1111 gm coins, where each coin contributes an extra 11 gm:

Excess weight=323−310=13 gm\text{Excess weight} = 323 - 310 = 13 \text{ gm}

We can express this excess weight as a sum of the powers of 22 corresponding to the number of coins picked from each bag:

1⋅x1+2⋅x2+4⋅x3+8⋅x4+16⋅x5=131 \cdot x_1 + 2 \cdot x_2 + 4 \cdot x_3 + 8 \cdot x_4 + 16 \cdot x_5 = 13

Since xi∈{0,1}x_i \in \{0, 1\}, this is equivalent to finding the binary representation of 1313:

13=8+4+1=23+22+2013 = 8 + 4 + 1 = 2^3 + 2^2 + 2^0

Comparing the coefficients, we get:

  • x1=1x_1 = 1 (Bag 1 has 1111 gm coins)
  • x2=0x_2 = 0
  • x3=1x_3 = 1 (Bag 3 has 1111 gm coins)
  • x4=1x_4 = 1 (Bag 4 has 1111 gm coins)
  • x5=0x_5 = 0

The bags containing 1111 gm coins are 1, 3, and 4.

The product of these labels is:

1×3×4=121 \times 3 \times 4 = 12

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Algorithm Design: Greedy Techniques questions