Page 2 of 2

Posted: Mon Aug 20, 2007 4:36 pm
by Jan

Code: Select all

Suppose there are 4 boxes and 4 destinations. And lets consider that f(0001) means that the cost where the 4th destination is used and there is only one box. f(0010) returns the cost where the 3rd destination is used with box 1.

So, f(1001) returns the min cost such that the first two boxes are used and the 1st and the 4th destinations are used.

So, f(1101) returns the min cost such that the first three boxes are used and the 1st, 2nd and the 4th destinations are used. So, the number of '1's means the number of boxes. Right?

So, f(1111) is our desired result. And suppose cost[i][j] means the cost to connect the ith box to the jth destination.

Now we can build a recurrence

f(1111) = min ( f(1110) + cost[4][4], f(1101) + cost[4][3], f(1011) + cost[4][2],
                f(0111) + cost[4][1] );
Hope it helps.

Re:

Posted: Wed Jun 11, 2008 9:10 am
by DJWS
polone wrote:There are a situation that some X may not be matched to every B.

So you should exam your cost list that shouldn't exist strange numbers.

Hope that help you~
I made assertions in my code and I found the # of B is equal to the # of X.
The problem statement does not mention the equality so we can not assume they are the same in fact.

Re: 10888 - Warehouse

Posted: Fri Aug 01, 2008 4:52 am
by andmej
Hi, I understand the DP solution explained above by Jan.

However, I don't understand the solution using min-cost max-flow algorithm.

Can somebody explain the idea a little deeper? Thanks.

Re: 10888 - Warehouse

Posted: Sun Aug 28, 2011 11:27 am
by Shafaet_du
Problem setter should have mentioned that number of destination==number of boxes.

Re: 10888 - Warehouse

Posted: Sun Aug 28, 2011 11:29 am
by Shafaet_du
try this:

Code: Select all

1
5 8
X...#..X
X#......
.BB#.#.X
..B#...#
X..B...B



output:

Code: Select all

21