Understanding solution to finding optimal strategy for game involving picking pots of gold

前端 未结 5 2001
深忆病人
深忆病人 2021-02-13 23:50

I am having trouble understanding the reasoning behind the solution to this question on CareerCup.

Pots of gold game: Two players A & B. There are pot

5条回答
  •  悲哀的现实
    2021-02-14 00:08

    Assume what you gain on your turn is x and what you get in all consequent turns is y. Both values represent x+y, where a assumes you take next pot (x=coin[start]) from the front and b assumes you take your next pot (x=coin[end]) from the back.

    Now how you compute y.

    After your choice, the opponent will use the same optimum strategy (thus recursive calls) to maximise his profit, and you will be left with a the smaller profit for the turn. This is why your y=min(best_strategy_front(), best_strategy_end()) -- your value is the smaller of the two choices that are left because the opponent will take the bigger.

    The indexing simply indicates the remaining sequences minus one pot on the front and on the back after you made your choice.

提交回复
热议问题