What is the problem with this recurrence relation ?

Правка en1, от anh1l1ator, 2015-12-12 17:34:28

I was trying to solve COURIER on spoj . [ Link ]

As the Sum of couriers to be send are only 12 I broke up it into 12 individual orders.

My state : F[i][mask] represents the minimum cost for completing all the couriers in mask with last courier activity completed being i.

Recurrence : F[i][mask] = minimum of ( k belongs to subset denoted by mask F[k][ subset — { i } th courier ] + Cost of going from end of k th courier to beginning of the i th courier + Cost of going from beginning to end ).

Now, My answer will be F[ x ][ all the couriers denotes by 11111... ] + Cost to go from end point of x activity to starting point

Base Case being for all subsets containing only one activity with cost = the cost of going to the end of the courier from starting point through the starting point of the courier.

The Cost for going from some point to other point is calculated via All pair shortest path (Floyd Warshall)

I have been trying it for 8 hours now , and my code doesn't give right output on sample case I don't know why !! Can someone point out the mistake in my method or recurrence or state ??

Just in case if you want to check out if there is some mistake in my code ?

http://ideone.com/FLhsog

I saw some solutions too online they had a different state but I think my state has every important information for transitions!! Moreover their solutions too had same kind of idea!!

Теги dynamic programming, graph, algorithm, debugging

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en1 Английский anh1l1ator 2015-12-12 17:34:28 1535 Initial revision (published)