5. 0 0 0 0 0 0
0 2 4 6 8 10
0 2 5 7 10 12
0 2 5 9 11 14
0 2 5 9 11 14
#If pieces of length is greater than the total length that’s why previous profit
and current profit are same
#If previous profit is greater than current profit that’s why we count previous
profit is the current profit
14
8. Pseudo Code
int priceOfLen[ ] = {0, 2, 5, 9, 6};
int maxProfit( n )
{
for (totalLen 1 to n)
{
tmp 0;
for (partLen 1 to totalLen)
{
thisProfit priceOfLen[partLen] + maxProfitOfLen[totalLen - partLen];
if (tmp < thisProfit)
{
tmp thisProfit;
partLenOfLen[totalLen] partLen;
}
}
maxProfitOfLen[totalLen] tmp;
}
return maxProfitOfLen[n];
}
9. Void Divisions( n )
{
while (n > 0)
{
print partLenOfLen[n] ;
n n - partLenOfLen[n];
}
}
Pseudo Code For Knowing The How We Have To Cut The Rod
0 1 2 3 4 5
priceOfLen[ ]
maxProfitOfLen[ ]
partLenOfLen[ ]