My friend and I were working on a problem on DP. The question was like this. There are 2 coal mines X, Y. You have 3 kinds of food packages A, B, C. Your aim is to send the packages (sequence of which is given to you) to X, Y so as to maximise the coal output.
coal output is decided like this:
for each mine, check the last 3 packages received. If they are all different, output = 3
if two are different, output = 2
else 1
e.g. if the food package sequence is ABCBCA
then you have to send the packages like this:
X: A, B, C = 1+2+3 Y: B, C, A = 1+2+3
total output = 12
(actually you could've sent all to one mine, to get the same max output)
now the doubt is:
we got this method
start from the first package (A here). See where you get the most output (X or Y) and send it there.
If both give the same output, do the same for the next package.
clarification: you must dispatch the food in the order of the sequence.
and it can be solved by greedy algorithm? I asked this on stackoverflow, and the fellow who answered said "it seems a simple DP program to me, i'll leave it to you"
Btw, are you at least convinced that our method works? Because we couldn't really think of any counterexample and the algorithm worked on the sample input