GATE / CS ARCHIVE

GATE CSE 2021 SET 1 / QUESTION 40

GATE CSE 2021 Set 1 Q40

Algorithms · Dynamic Programming · Full GATE CSE 2021 Set 1 paper

GATE 2021 Set 1, Q40 2 marks · MSQ
Report issue

Dynamic Programming

Question 40, GATE 2021: Let R_n be the maximum revenue from cutting a rod of integer length n into one or more integer-length pieces. Prices for lengths 1,...,7 are 1,5,8,9,10,17,18. Select all true statements: A R7=18; B R7=19; C R7 is achieved by three different solutions; D no three-piece solution achieves R7. Different piece orders are not different cutting solutions.
Tap to enlarge
Select all that apply
Answer & solution

Official answer: A; C

With R0=0 and Rn=max1≤i≤n(p[i]+Rn−i), the values R1,…, R7 are 1, 5, 8, 10, 13, 17, 18. Revenue18 is achieved by exactly the three unordered partitions 7; 6+1; 3+2+2. The last uses three pieces, so D is false, and 19 is not attainable. Hence A, C. Different orders of the same piece lengths are not counted as distinct cutting solutions.

Dynamic-programming pseudocode: R[0]=0; for length=1..7: R[length]=max(price[i]+R[length−i] for i=1..length). At length 7 the candidates for first piece sizes 1..7 are 18,18,18,17,15,18,18. Backtracking optimal candidates and sorting piece lengths gives {7},{1,6},{2,2,3}; different first-piece choices can lead to the same sorted partition, so count each only once. The recurrence is exhaustive because every nonempty cutting solution has some first piece and an optimally solved remainder.

Original paper, page 34 · Answer key