A Delivery Partner can deliver multiple orders to a Tech Park at the same time. On the way back to the starting point, the
Delivery Partner may pick up additional orders for the next trip to the Tech Park. A map of restaurant locations where orders are
placed, has been created and represented as a square matrix.
The matrix is filled with cells, and each cell will have an initial value as follows:
The rules of motion are as follows:
path cell.
The ultimate goal is to collect and deliver as many orders as possible.
Constraints:
n <= 100
For example, consider the following grid:
Input:
0 1
-1 0Output:
1Start at the top left corner. Move right one, collecting an order. Move down one to the Tech Park. Cell (1, 0) is blocked, so the return
path is the reverse of the path to the Tech Park. All paths have been explored, and 1 order was collected.
Input:
0 1 -1
1 0 -1
1 1 1Output:
5Other two questions: (edit)
Ram and Shyam are very hungry. Ram can only eat food item of type 1 and Shyam can only eat food item of type 2. There are n packets (<= 10^5). For each packet we are given its cost, and two booleans representing if it contains food of type 1 and food of type 2 respectively. Both Ram and Shyam need at least k food items each to survive. Find the minimum cost needed for both Ram and Shyam to survive. (return -1 otherwise).
Input:
8 4 // n k
7 1 1 // cost, type1, type2
2 1 1
4 0 1
8 1 1
1 0 1
1 1 1
1 0 1
3 0 0Output:
18