如果玩家最多可以获得4个硬币,那么赢得比赛的策略

时间:2015-12-03 04:03:29

标签: algorithm dynamic-programming

两名玩家正在玩游戏,每个玩家必须在每个回合中选择1,2,3或4个硬币。总共有n个硬币。拿起最后一枚硬币的玩家,他赢了。设计一个赢得比赛的策略。

解决问题的算法策略是什么,这样我才能赢得游戏,假设我是其中一员?

1 个答案:

答案 0 :(得分:8)

为前10场比赛制作一张桌子;会有一个明确的模式。如果有......

1 coin: take 1, you win
2 coins: take 2, you win
3 coins: take 3, you win
4 coins: take 4, you win
5 coins: you lose (whatever you choose, the opponent wins by rule 1-4)
6 coins: take 1, opponent loses by rule 5
7 coins: take 2, opponent loses by rule 5
...
10 coins: you lose (whatever you choose, the opponent wins by rule 6-9)
11 coins: take 1, opponent loses by rule 10
...

所以,你总是拿n % 5枚硬币,除非它是0(如果它是0,否则无论你做什么都会让对手完全失败,所以拿1来最大化他的机会犯了错误。)