Skip to main content

GATE CSE 2021Algorithms › Greedy Method, Dynamic Programming & Algorithm Design TechniquesVerified

GATE CSE 2021 PYQ: Define R n R_n R n ​ to be the maximum amount earned by cutting a rod of length n n n meters into one or…

Define RnR_n to be the maximum amount earned by cutting a rod of length nn meters into one or more pieces of integer length and selling them. For i>0i>0, let p[i]p[i] denote the selling price of a rod whose length is ii meters. Consider the array of prices:

p[1]=1,p[2]=5,p[3]=8,p[4]=9,p[5]=10,p[6]=17,p[7]=18\text{p}[1]=1,\text{p}[2]=5,\text{p}[3]=8,\text{p}[4]=9,\text{p}[5]=10,\text{p}[6]=17,\text{p}[7]=18Which of the following statements is/are correct about R7R_7?

  1. A
    R7=18R_7=18
    Correct answer
  2. B
    R7=19R_7=19
  3. C
    R7R_7 is achieved by three different solutions
    Correct answer
  4. D
    R7R_7 cannot be achieved by a solution consisting of three pieces

Answer

(A, C) R 7 = 18 R_7=18 R 7 ​ = 18; R 7 R_7 R 7 ​ is achieved by three different solutions

Approach

Compute $R_7$ by considering all integer partitions of 7, since the rod must be cut into pieces of integer length. The maximum total selling price over all partitions is $R_7$. Use the given price array and compare each partition sum.

The maximum revenue for a rod of length 7 is $R_7=18$, attained by the cuts {7}, {6,1}, and {3,2,2}. Thus statements A and C are correct, while B and D are incorrect.

Reviewed by GateIQ Editorial Team: IIT & IISc Alumni.