By Mhammad1, history, 8 years ago, Hello everyone

The problem:

Given 2d array with numbers inside each cell, you should maximize the cost to get from top left (1,1) to bottom right (N,M) with three paths, When you pass to cell(i,j) the cost inside it will be removed for the next paths.

You're only allowed to move down or right.

How can I solve something like this?

I've read the tutorial here TopCoder Tutorial but I didn't understand the whole concept.  Comments (5)
 » You realise that every time you move downward or to the right, either x or y is increased by 1. So after taking K steps, (x-1) + (y-1) = K.Therefore, we can represent this DP state as (K, x of first path, x of second path, x of third path) = number of apples received after the first K steps of the three paths. This is O(N^4), which fits the limit of the problem.Since each x can come from either the same x coordinate or x-1 in the previous diagonal, the transition would be: f(k, x1, x2, x3) = max(f(k-1, x1, x2, x3), f(k-1, x1, x2, x3-1), f(k-1, x1, x2-1, x3) ... f(k-1, x1-1, x2-1, x3-1)) + (arr[x][k-x] for each unique x among x1, x2, x3) Therefore we can solve the problem in O(N^4).
•  » » 8 years ago, # ^ | ← Rev. 2 →   Can we use the index of row of x1 so the recurrence will be: f(y1, x1, x2, x3) and then we can get the other rows by (y1+x1) ?To be more specific, why do we use the steps number not the index of one row?
•  » » » I think when K >= N, the index of the first row remains at N if I am not mistaken.
 » 8 years ago, # | ← Rev. 4 →   Note: you can also solve this using mincost maxflow.
 » Can we process the 3 path one after the other i.e. 1. find the path with max cost to get from top,left to bottom,right 2. update the cells covered by previous path as 0 (we have used up all the cost) 3. repeat #1 and #2 for second and third pathI don't think the choice of path1 affects path2 and so on, since they wouldn't intersect. What do you guys think?