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

前端 未结 5 1992
深忆病人
深忆病人 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:06

    a and b here represent the maximum A can get by picking the starting pot or the ending pot, respectively.

    We're actually trying to maximize A-B, but since B = TotalGold - A, we're trying to maximize 2A - TotalGold, and since TotalGold is constant, we're trying to maximize 2A, which is the same as A, so we completely ignore the values of B's picks and just work with A.

    The updated parameters in the recursive calls include B picking as well - so coin[start] represents A picking the start, then B picks the next one from the start, so it's start+2. For the next call, B picks from the end, so it's start+1 and end-1. Similarly for the rest.

    We're taking the min, because B will try to maximize it's own profit, so it will pick the choice that minimizes A's profit.

    But actually I'd say this solution is lacking a bit in the sense that it just returns a single value, not 'an optimal strategy', which, in my mind, would be a sequence of moves. And it also doesn't take into account the possibility that A can't win, in which case one might want to output a message saying that it's not possible, but this would really be something to clarify with the interviewer.

提交回复
热议问题