GateAI
Dynamic Programming

GATE CSE 2021 Set 1 · Q40

MSQ2 marksMedium

Time

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]\text{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] = 18 Which of the following statements is/are correct about R7R_7?

Select all that applyOne or more correct

Pick every correct option

Solution

Step-by-step verified solution

Official answer: A) R7 = 18; C) R7 is achieved by three different solutions.

Dynamic Programming

We can compute RnR_n for n=1,2,…,7n = 1, 2, \dots, 7 using the dynamic programming recurrence:

Rn=max⁡1≤i≤n(p[i]+Rn−i),with R0=0R_n = \max_{1 \le i \le n} (\text{p}[i] + R_{n-i}), \quad \text{with } R_0 = 0

Evaluating iteratively:

  • R1=p[1]=1R_1 = \text{p}[1] = 1

  • R2=max⁡(p[2],p[1]+R1)=max⁡(5,1+1)=5R_2 = \max(\text{p}[2], \text{p}[1] + R_1) = \max(5, 1+1) = 5

  • R3=max⁡(p[3],p[1]+R2,p[2]+R1)=max⁡(8,1+5,5+1)=8R_3 = \max(\text{p}[3], \text{p}[1] + R_2, \text{p}[2] + R_1) = \max(8, 1+5, 5+1) = 8

  • R4=max⁡(p[4],p[1]+R3,p[2]+R2,p[3]+R1)=max⁡(9,1+8,5+5,8+1)=10R_4 = \max(\text{p}[4], \text{p}[1] + R_3, \text{p}[2] + R_2, \text{p}[3] + R_1) = \max(9, 1+8, 5+5, 8+1) = 10

  • R5=max⁡(p[5],p[1]+R4,p[2]+R3,p[3]+R2,p[4]+R1)=max⁡(10,1+10,5+8,8+5,9+1)=13R_5 = \max(\text{p}[5], \text{p}[1] + R_4, \text{p}[2] + R_3, \text{p}[3] + R_2, \text{p}[4] + R_1) = \max(10, 1+10, 5+8, 8+5, 9+1) = 13

  • R6=max⁡(p[6],p[1]+R5,p[2]+R4,p[3]+R3,p[4]+R2,p[5]+R1)=max⁡(17,1+13,5+10,8+8,9+5,10+1)=17R_6 = \max(\text{p}[6], \text{p}[1] + R_5, \text{p}[2] + R_4, \text{p}[3] + R_3, \text{p}[4] + R_2, \text{p}[5] + R_1) = \max(17, 1+13, 5+10, 8+8, 9+5, 10+1) = 17

  • R7=max⁡(p[7],p[1]+R6,p[2]+R5,p[3]+R4,p[4]+R3,p[5]+R2,p[6]+R1)=max⁡(18,1+17,5+13,8+10,9+8,10+5,17+1)=18R_7 = \max(\text{p}[7], \text{p}[1] + R_6, \text{p}[2] + R_5, \text{p}[3] + R_4, \text{p}[4] + R_3, \text{p}[5] + R_2, \text{p}[6] + R_1) = \max(18, 1+17, 5+13, 8+10, 9+8, 10+5, 17+1) = 18

Thus, R7=18R_7 = 18, so A is correct and B is incorrect.

Now find all integer partitions of 77 that yield total revenue equal to 1818:

  1. A single piece of length 77: p[7]=18\text{p}[7] = 18

  2. Two pieces of lengths 11 and 66: p[1]+p[6]=1+17=18\text{p}[1] + \text{p}[6] = 1 + 17 = 18

  3. Three pieces of lengths 2,2,2, 2, and 33: p[2]+p[2]+p[3]=5+5+8=18\text{p}[2] + \text{p}[2] + \text{p}[3] = 5 + 5 + 8 = 18

Hence, R7R_7 is achieved by exactly three distinct multiset cuts, making C correct and D incorrect (since {2,2,3}\{2, 2, 3\} consists of 33 pieces).

Try the question first, then check your work.

Think the official key or this write-up is wrong?

Report error or challenge

Examiner trap

The misconception this question tests

This Dynamic Programming previous year question is Q40 of the GATE CSE 2021 Set 1 paper. Find more GATE CSE PYQs on Dynamic Programming in Algorithms, or browse all GATE CSE PYQs.

Free diagnostic

Where do you stand for GATE?

Take the 20-minute diagnostic: the 3 topics that cost you the most marks, and a rank range. Or sit 5 related Dynamic Programming PYQs now with no account.

One GATE CSE PYQ every morning

An official question by email at 7 AM IST, with a link to its verified solution. Unsubscribe in one click.

Dynamic Programming in GATE CSE

Dynamic Programming has 7 GATE CSE PYQs across 6 papers from 2011 to 2026. This is the only 2-mark MSQ among them, and it is the only one in GATE CSE 2021 Set 1.

How GATE tests Dynamic Programming

More from GATE CSE 2021 Set 1

Share this solution

A plain-text card for WhatsApp or Telegram study groups.

GateAI solution cardGATE CSE 2021 Set 1 · Q40 · MSQ

Define Rn to be the maximum amount earned by cutting a rod of length n meters into one or more pieces of integer length and selling them. For i > 0, let p[i] denote the selling price of a rod whose length is i 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 Which of the following statements is/are correct about R7?

Topic-wise GATE CS PYQs with verified steps

Independent practice explanation verified by the GateAI team. GATE is conducted by the IITs; question text follows the official paper.