edited by
19,558 views
37 37 votes

Define $R_n$ 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:

$$\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 $R_7$?

  1. $R_7=18$
  2. $R_7=19$
  3. $R_7$ is achieved by three different solutions
  4. $R_7$ cannot be achieved by a solution consisting of three pieces

5 Answers

43 43 votes

A & C should be correct

  • $1^{st}$ Solution $: p[2];p[3];p[2] = 5+8+5 = 18$
  • $2^{nd}$ Solution $: p[7] = 18$
  • $3^{rd}$ Solution $: p[6]; p[1] = 17+1 = 18$
4 4 votes

Answer is (A) & (C)
This question is similar to 0/1 Knapsack.

1. Include 7 length rod  => Profit of 18.

Now, traverse through the path where we don't include 7.

2. Include 6.

   Only 1 case (6,1) again leads to a profit of 18.

Now, traverse through the path where we don't include 6.

3. Include 5.

   Two cases: (5,2) => Profit 15 and (5,1,1) => Profit 12

4. Dont include 5, Include 4.
   Three Cases:
      (4,3) => 17
      (4,2,1) => 15
      (4,1,1,1) => 12

5. Dont include 4, Include 3
      (3,2,2) => 18
      (3,2,1,1) => 15
      (3,1,1,1,1) => 12

6. Dont include 3, Include 2
     (2,2,2,1) => 16
     (2,2,1,1,1) => 13
     (2,1,1,1,1,1) => 10

7. All 1s => 7

3 3 votes

ANSWER : A,C

1st : directly from p[7]= 18

2nd  : p[6] + p[1]= 18 

3rd : p[2] + p[3] + p[2]= 5+8+5= 18

and these are the only 3 ways you can try other combinations but these only are gives maximum . 

3 3 votes

It is not difficult to see that the optimal solution for the rod cutting problem is determined by the recurrence:

$R(n) = max_{0<=i<= n} (R(n-i) + p[i])$.

$R(0) = 0$

We can see that a bottom-up dynamic programming approach will be easier here, starting from n = 1. The table is filled below, step-by-step.

$R(1) = max(R(0) + p[1]) = 1$

$R(2) = max(R(0) + p[2], \ R(1) + p[1]) = max(5, 1+1) = 5$.

$R(3) = max(R(0) + p[3], R(1) + p[2], R(2) + p[1]) = max(8, 1+5, 5 + 1) = 8$.
 
 
 n = 1n = 2n = 3n = 4n = 5n = 6n = 7
R(n)158    
 
 
$R(4) = max(R(0) + p[4], R(1) + p[3], R(2) + p[2], R(3) + p[1]) = max(9, 1+8, 5 + 5, 8+1) = 10$
 
 n = 1n = 2n = 3n = 4n = 5n = 6n = 7
R(n)15810   
 
 
$R(5) = max(R(0)+p[5], R(1) + p[4], R(2) + p[3], R(3) + p[2], R(4) + p[1]) = max (10, 1+9, 5+8, 8+5, 10+1) = 13$.
 
 n = 1n = 2n = 3n = 4n = 5n = 6n = 7
R(n)1581013  
 
$R(6) = max(R(0) + p[6], R(1) + p[5], R(2) + p[4], R(3) + p[3], R(4) + p[2], R(5) + p[1]) = max(17, 1+10, 5+9, 8+8, 10+5, 13 + 1) = 17$ 
 
 n = 1n = 2n = 3n = 4n = 5n = 6n = 7
R(n)158101317 
 
 
$R(7) = max(R(0) + p[7], R(1) + p[6], R(2) + p[5], R(3) + p[4], R(4) + p[3], R(5) + p[2], R(6) + p[1])=$
$ max(18, 1+17, 5+10, 8+8, 13+5, 17+1) = $
$ max(18, 18, 15, 16, 18, 18)$.
 
Thus $R(7) = 18$. 
We see that $R(7)$ is obtained by four different values of 18. Option D cannot be correct as split (2, 3, 2) produces an optimal solution, which can be identified using the calculations above.
 
Therefore, only options A and C are correct.
 
 
0 0 votes

😁 Its the easiest question I have seen in a long time 

Ans : A and C 

18 is the maximum you can get in profit by taking (7) OR (6,1) OR (2,3,2)= 18

as you can see these are 3 Different solutions shown above hence satisfies 2 given options  

edited by
Answer:
Position:
Show:

Related questions

0 0 votes
1 1 answer
817
817 views
admin asked Jul 21, 2022
817 views
Which of the following methods can be used to solve the Knapsack problem?Brute force algorithm RecursionDynamic programmingBrute force, Recursion, and Dynamic Programming
1 1 vote
1 1 answer
650
650 views
soujanyareddy13 asked Jan 9, 2022
650 views
Given the following characteristics :Optimal substructureOverlapping subproblemsMemorizationDecrease and conquerDynamic programming has the following characteristics :$\t...
63 63 votes
4 answers 4 answers
18.2k
18.2k views
Arjun asked Feb 18, 2021
18,156 views
Consider a $\textit{dynamic}$ hashing approach for $4$-bit integer keys:There is a main hash table of size $4$.The $2$ least significant bits of a key is used to index in...
0 0 votes
1 1 answer
493
493 views
admin asked Jul 21, 2022
493 views
In dynamic programming approach the optimum solution is calculated in the following way:Divide and conquerTop up fashionBottom-up approachMixed approach