algorithm - Minimum cost of choosing items from n buckets -
i have n numbers of buckets. each bucket contains 3 items - i1, i2 & i3. each item has own cost associated. have pick items each bucket such items picked 2 consecutive buckets not same. algorithm find minimum cost of picking n items n such buckets?
i can think recursive brute force solution explore costs , find out minimum of them.
what can efficient algorithm solve problem?
the state space dynamic programming can defined follows.
c[i,j] = minimum cost attainable choosing items item each bucket in {1,...,i} each item index different item index in previous bucket , item in last bucket j in {1,...,n} , j in {1,2,3}
for state space, obtain following recurrence relation, i[j,k]
each j
in {1,...,n}
, k
in {1,2,3}
denotes cost of k
-th item in bucket k
.
c[i,j] = min { min { c[i-1,2], c[i-1,3] } + i[i,1]: j = 1, min { c[i-1,1], c[i-1,3] } + i[i,2]: j = 2, min { c[i-1,1], c[i-1,2] } + i[i,3]: j = 3 }
the initial states can filled assigning
c[1,1] = i[1,1], c[1,2] = i[1,2], c[1,3] = i[1,3]
and after iteratively filling state space, desired value can found evaluating folowing expression.
min { c[n,1], c[n,2], c[n,3] }
Comments
Post a Comment