两个玩家正在玩游戏,其中每个玩家必须在每个回合中选择1,2,3或4个硬币.总共有n个硬币.拿起最后一枚硬币的玩家,他赢了.设计一个赢得比赛的策略.
什么是解决问题的算法策略,以便我可以赢得比赛,假设我是其中一个球员?
为前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来最大化他犯错误的机会).