I assume that you know all the numbers that you give in the example when you run the algorithm, and do not get t2 after the end of t1, etc.
I also suggest that two lines can shoot at once, although this does not really matter.
The first time you select, you can assign a value to each cell, which is the value of the OfBirdsInCell-time sum.
This gives you two cells with values โโof 1 being S1t1, S1t2, the rest are below.
Only the time of the last cell is calculated in your account, so choosing the earliest will delete the time on it for the next round, making it the most valuable time. This is the first choice.
Now remove the birds killed in this first selection from all the cages.
Repeat the process of determining the value for the remaining cells. In your example, cell S3t2 will give the highest result: 0.
Repeating this process, you get the most valuable cells in the very near future.
One important bit in your example does not apply: if your first most valuable choice is at t2, the next most valuable choice may be at t1 or t2, so you should consider this. However, since t2 has already been confirmed, you should not consider their time for their value.
I never wrote in python, I'm just here because of an algorithm tag, so there is java / c-like pseudo code here:
highestCellTime = 0; while(birdsRemain) { bestCell; for(every cell that has not been picked yet) { currentCellValue = amountOfBirds; if(currentCellTime > highestCellTime) { currentCellValue = currentCellValue - currentCellTime; } if(currentCellValue < bestCellValue) { bestCell = thisCell; } else if(currentCellValue == bestCellValue && currentCellTime < bestCellTime) { bestCell = thisCell; } } addCellToPicks(bestCell); removeBirdsFromOtherCells(bestCellBirds); }
If I didnโt forget something, now you have the optimal combination of cells in your collection of choice.
Hope this code makes sense to a python programmer. If someone can translate it, please do it! And remove that bit of text and the earlier mention of java / c pseudo code when you do this.
EDIT by OP : The first version and does not contain the best cells. I suppose this should be a mistake in my code, but nonetheless I post here.
import math cellsNotPicked = range(0,12) cellToBird = { 0: [1, 2], 1: [], 2: [1], 3: [1,2,3], 4: [1], 5: [3,4], 6: [4], 7: [1,2], 8: [], 9: [], 10: [3,4], 11: [1,2,3,4] } picks = [] def getCellValue(cell): return len(cellToBird[cell]) def getCellTime(cell): return int(math.floor(cell / 3)) + 1 birdsRemain = 4 while(birdsRemain > 0): bestCell = 0; for thisCell in cellsNotPicked: currentCellValue = getCellValue(thisCell); currentCellTime = getCellTime(thisCell) highestCellTime = getCellTime(bestCell) if(currentCellTime > highestCellTime): currentCellValue = currentCellValue - currentCellTime; if(currentCellValue < getCellValue(bestCell)): bestCell = thisCell elif (currentCellValue == getCellValue(bestCell)) and (currentCellTime < getCellTime(bestCell)): bestCell = thisCell picks.append(bestCell) cellsNotPicked.remove(bestCell) birdsToRemove = cellToBird[bestCell] for key in cellToBird: for bird in birdsToRemove: try: cellToBird[key].remove(bird) birdsRemain -= 1 except: pass print picks