I am trying to solve the stopping postman problem, but I’m not able to find any algorithm to solve it. The problem is this:
There are n houses numbered 1 to n, and n postman, each having n
letters to be posted in each house. The postmaster has decided a plan
such that each postman visits each house exactly once at a different
time, i.e. there is at most one postman in any house at any time.
Since no postman like any other , postmaster wants that no postmaster
meet any other during delivery of posts to n houses. So he wants a
postman to stop posting after a particular house. That is, Postmaster
wants to find a sequence stop such that the i-th postman will
stop posting after stop[i]-th house once he visits that house. As
he wants to ensure that there is at maximum one post in each house, he
must choose the sequence stop such that if postman A visits house
H at time T, and he stops posting after the house, then no other
postman visit house H after time T. Help postmaster to find such a
sequence stop.
The input is given as follows:
Firstly n (1 ≤ n ≤ 100), indicating the number of postman and houses. Then n lines follow, with each line containing n positive integers. The j-th integer in i-th line indicates the time when the i-th postman will visit the j-th house.
Example:
n = 3
The sequence is :
1 2 3
4 5 6
7 8 9
The outputted stop array should be:
3 2 1, i.e. 1st postman stops posting in 3rd house, 2nd in 2nd house and 3rd in first house.
What algorithm should I use to solve this problem?
Update, my last answer was wrong.
New solution:
on each step find min number in each row, then take the max of them and that will be the stop for i-th postman. on each next step don’t consider that postman anymore
For the sample you provided:
1st step we find 1 4 7, maximum of them is 7 so for the 3rd postman stop is at 1st house(stop[3] = 1)
after that we don’t consider 1st column and 3rd row
2nd step we find 2 and 5, max is 5 so – stop[2] = 2;
3rd step stop[1] = 3;
So, why is it true, if we selected the right number on some step we know that for any number in the same column, it’s either less than our number (that means it won’t cause problem later) or bigger that our number, but that row has the number which is less than it WILL be selected later, so that that the bigger number in our column won’t be used
And for the example @Wayne Rooney provided
1st step find 1, 6, 3, select 6
2nd step find 1, 3 select 3
3rd step 1
answer: 1, 2, 3