2
4
A
3
7
B
4
6
3
C 2
4
4
D
1
3
E 1
4
F
3
4
3 3
G
E or 4 H
7F
E 1
4
6
4
11 2C or 7 E
7 I
3
6
D4
A
C 2
F
3
4
3
11
B
4
D
8
3 3
G
3
E or 6
3 J
H 3
J
4
I
4
A
D
i.e.
or
A
A
C
D
E
E
H
H
J
J
or
I
with optimum
value 11.
y1
y2
y3
y4
where y4=J
f n ( xn , yn )
Thus
Fn ( xn ) min f n ( xn , yn ) f n ( xn , y )
*
n
where
fn (xn, yn) = immediate cost (stage n) +
minimum future cost (stages n+1 onward)
cxn , yn Fn 1 ( xn 1 )
Solution
n=4. Here F4(x4) = c(x4, y4)
(There is only one entry to minimize)
x4
H
I
F4(x4
)
3
4
y4*
J
J
y3
f3(x3, y3)
H
E
F
G
cx3 , y3 + F4(x4)
1+3
=4
6+3
=9
3+3
=6
I
4+4
=8
3+4
=7
3+4
=7
F3(x3)
y3*
n=2. Here
f 2 ( x2 , y2 ) cx2 , y2 F3 ( x3 )
y2
x2
B
C
D
f2(x2, y2)
E
7+4=
11
3+4=
7
4+4=
8
4+7=
11
2+7=
9
1+7=
8
6+6=
12
4+6=
10
5+6=
11
F2(x2)
y2*
11
E or F
E or F
n=1. Here
f1 ( x1 , y1 ) cx1 , y1 F2 ( x2 )
f1(x1, y1)
y1
x1
2+11=13
4+7=11 3+8=11
F1(x1)
y1*
11
C or D
H
J
A
D
i.e.
or
or
Forward Recursion
The same problem can be done by starting
from stage 1 and ending with stage 4 as
follows:
n=1 F1 ( x1 ) f1 ( x1 , y1 ) c ( A, x1 )
y0
x1
f1(x1, y1)
F1(x1)
y0*
A
2
y2
x2
f2(x2,y2)
B
E
F
G
7+2=
9
4+2=
6
6+2=
8
3+4=
7
2+4=
6
4+4=
8
F2(x2)
y2*
4+3=
7
1+3=
4
3+3=
6
7
4
C or
D
D
y3
x
3
H
I
f3(x3,y3)
E
1+7=
8
4+7=
11
6+4=
10
3+4=
7
3+6=
9
3+6=
9
F3(x3)
y3*
y4
f4(x4, y4)
F4(x4)
y4*
H
I
3+8= 4+7= 11 H or I
11
11
H
J
A
D
Characteristics of DP problems
We pay special attention to the three basic
elements of a DP model:
Definition of the stages
Definition of the alternatives at each stage
Definition of the states for each stage
Points to be noted:
The definition of the state is the most subtle.
We find it helpful to consider the following
questions:
What relations bind the stages together?
What information is needed to make
feasible decisions at the current stage
without re examining the decision made at
previous stages?
Knapsack problem
This classical problem deals with the
situation in which a hiker must decide on the
most valuable items to carry in a backpack.
max
mi =0,1, wx
{rimi + Fi+1(xi+1)}
xi W
(where Fn+1(xn+1) = 0)
i = 1,2,, n
xi W
xi
wi
i = 1,2,, n
w1 4, r1 70, w2 1, r2 20,
w3 2, r3 40, W 6.
Stage 3
m3 can assume values 0,1,2,3.
An alternative is feasible only if
w3 m3 x3
F3(x3)
m3 *
0
1
2
3
4
5
6
0
0
0
0
0
0
0
40
40
40
40
40
80
80
80
120
0
0
40
40
80
80
120
0
0
1
1
2
2
3
Stage 2. F2(x2)=max
{20m2 + F3(x2 - m2)} max m2=[6/1]=6
m
20m2 + F3(x2-m2)
(w2 = 1, r2 = 20)
2
x2
m2=0
F2(x2)
m 2*
20
20
0+40
= 40
20+0
= 20
40
0 or 2
0+40
= 40
20+40 40+0
= 60 = 40
60+0
= 60
60
1 or 3
0+80
= 80
20+40 40+40
= 60 = 80
60+0
= 60
80+0
= 80
80
0 or 2
or 4
0+80
= 80
80+0
= 80
100+0
= 100
100
1 or 3
or 5
120
0 or 2
or 4
or 6
40+0
= 40
(w1 = 4, r1 = 70)
m1=0
m1=1
F1(x1)
m1*
0
1
2
0+0 = 0
0+20 = 20
0+40 = 40
0
20
40
0
0
0
0+60 = 60
60
0+80 = 80
70+0 = 70
80
100
120
Optimal allocation:
m1 0, m2 0, m3 3
or
m1 0, m2 2, m3 2 or
m1 0, m2 4, m3 1 or
m1 0, m2 6, m3 0
Course
Study
days
1
2
3
4
3
5
6
7
5
5
6
9
2
4
7
8
6
7
9
9
Solution
There are four stages. At stage i, let xi denote
the number of days left for study. Let yi denote
the number of days allocated for course i.
Let ri(yi) be the return (= grade points got)
when yi days are allocated to course i.
Let Fi(xi) be the optimum return for stages
i, i+1, , 4.
F4(x4)
6
7
9
9
y4*
1
2
3
4
Stage 3:
x3 = 2,3,4,5
y3 x3
2
3
4
5
2+6=
8
2+7=
9
2+9=
11
3
-
4+6=
10
4+7= 7+6=
11
13
2+9= 4+9= 7+7=
4
-
F3(x3
)
8
y3*
10
13
8+6=
14
3 or
Stage 2: x2 = 3, 4, 5, 6
F2(x2) = max {r2(y2) + F3(x2 y2)}
y2 x2
1
2
3
5+
8=13
5+10=1 5+8
5
=13
5+13=1 5+10 6+10
8
=15 =16
4
-
F2(x2
)
13
y2*
15
18
F1(x1)
y1*
16
19
21
23
2 ) + F (x
3- y )
r1(y
1
2 1
1
3+13
=16
3+16 5+13
5
=19
=18
3+18 5+15
6
=21
=20
3+19 5+18
7
=23
Optimum=22
Solution:
6+13
=19
6+15 7+13
y=21
= 2, y=20
= 1,
y3 = 3, y4 = 1
Optimum Total Grade Points = F1(7) = 23
1
D2
D3
D4
Tot Gr
pts
3+5+2+9=19
3+5+4+9=21
3+5+7+7=22
3+5+8+6=22
3+5+2+9=19
3+5+4+7=19
D1
D2
D3
D4
Tot Gr
pts
3+5+7+6=21
3+6+2+7=18
3+6+4+6=19
3+9+2+6=20
5+5+2+9=21
5+5+4+7=21
5+5+7+6=23
D1
D2
D3
D4
Tot Gr
pts
5+5+2+7=19
5+5+4+6=20
5+6+2+6=19
6+5+2+7=20
6+5+4+6=21
6+5+2+6=19
7+5+2+6=20
zy y y
subject to
y1 y2 y3 30,
2
1
2
2
2
3
y1, y2 , y3 0
Solution:There are three stages: in stage i, we
select the variable yi. At stage i, we are in state
xi = the sum of the variables yi yet to be
decided. Thus x1 y1 y2 y3 x1 y1 x2
x2 y2 y3 x2 y2 x3
x3 y3
x
and so optimal return
3 3
3
n = 2: Here F2 ( x2 ) min{y22 F3 ( x2 y2 )}
y
2
min{y22 ( x2 y 2 ) 2 }
y2
y2*
x22
and F2 ( x2 )
2
x2
2
n = 1: Here F1 ( x1 ) min{y12 F2 ( x1 y1 )}
y
1
min{y12 ( x1 y1 ) 2 }
y1
x1
Using calculus, we find optimal y
3
*
1
x12
F1 ( x1 )
3
Since x1 30, F1(x1) is minimum when x1 = 30