algorithm - Need help to decide a game strategy -


i'd know strategy should used solve following problem.

problem statement

there 2 coal mines, each employing group of miners. our job send food shipments mines. every time shipment of food arrives @ mine, miners produce amount of coal. there 3 types of food shipments: meat, fish , bread.

every time new shipment arrives mine, consider new shipment , previous 2 shipments (or fewer if there haven't been many) , then:

  • if shipments of same type, produce 1 unit of coal
  • if there 2 different types of food among shipments, produce 2 units of coal.
  • if there 3 different types of food, produce 3 units of coal.

the types of food shipments , order in sent known beforehand.

input

you given types of food shipments, in order in sent.

goal

the goal maximize coal output. done determining shipment should go mine. 2 mines don't have receive same number of shipments (in fact, permitted send shipments 1 mine).

example

for shipment order: mbmffb, expected output (maximum possible coal output) 12.

the logic use wrong:

m -> mine 1 = 1 coal unit(s)  b -> mine 1 = 2 "  m -> mine 2 = 1 "  f -> mine 1 = 3 "  f -> mine 2 = 2 "  b -> mine 2 = 3 " 

since first day, mine 1 had 1 type of food.

i can see simple dynamic programming algorithm, i'll leave you.

a simple hint: each shipment, can send either mine 1 or 2; after sending it, matters just:

  1. the amount of mine has been mined;
  2. the previous 3 shipments.

so there @ (3 ^ 3) ^ 2 = 729 shipment configurations, , each of these optimal amount of coal. in each step compute these configurations, , in end answer.


Comments