SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
Anany Levitin
Chapter:
Dynamic Programming
Exercise:
8.1 Exercise
Question:2 | ISBN:9780132316811 | Edition: 3

Question

Solve the instance 5, 1, 2, 10, 6 of the coin-row problem.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer

Procedure : 1) There is a row of n coins whose values are some positive integers C1,C2,C3,.....Cn not necessarly distinct 

2) The objective is to pick up the Maximum amount of money subject to the constraint that no two coins adjacent in the intial row can be picked up

3)  To find F(n)= Max{Cn+F[n-2],F[n-1]} for all n>1, where F[0]=0 and F[1]= C1

input Array : C[1,2,3,4,.......] of positive intigers indicating the coin values

Output Array: The maximum amount of money that can be picked up 

 

 

 

 Final table Coin Row problem for the instances 5,1,2,10,6
Index 0 1 2 3 4 5
    Coin   (C) 0 5 1 2 10 6
    F values for every loop ( F) 0 5 5 7 15 15
History   C1   -  C3 C4    -
Maximum Value of Coins to be taken     F[1] F[1] F[2] F[4]

                                 For calculating the F value we have to generate another table:

                                 

F(Index) Max Value
F[0]   0
F[1]   C1 = 5
F[2] Max(C2+F[0],F[1])=> Max(1+0,5)= 5     {We got this value From F[1]}
F[3] Max(C3+F[1],F[2])=> Max(2+5,5)= 7     {We got this value while adding  C3 to F[1]}
F[4] Max(C4+F[2],F[3])=> Max(10+5,7)= 15     {We got this value while adding C4 to F[2]}
F[5] Max(C5+F[3],F[4])=> Max(6+7,15)= 15     {We got this value  F[4]}

 

 

 

 

 

 

 

From  the Starting table we have calcutated that C1 and C4 are the coins will give maixmum value, C1 +C4 = 5+10 =15

 

0 0

Discussions

Post the discussion to improve the above solution.