GfG QA is closing soon... Please refer PRACTICE or GfG now on wards !!

Minimum robots needed puzzle programming

So, I have a puzzle. Let's assume that we have a grid n * m and that in each of it's cells there may or may not be a diamond. Each robot can only move to the right or down at any given moment. No diagonal movements. What is the minimal number of robots needed to get all the diamonds? I thought that if each robot grabbed teh max it could each time, all would be well, but alas that is not the case. In the following example I will illustrate why my solution is not always correct. Let's assume that a diamond is a 'D' and that an empty cell is a '.'

........
..D..D..
DD.D..DD
.......D
...DD...
.......D
........

If we use my way it takes 3 robots but there is a way with 2 robots. Could one come up with a working algorithm?

asked Jan 11, 2016 by Dr. X

First Robot:

..D..D.

         DD

            D

             .

             D

Second Robot :

DD.D

       . 

       DD

...