【发布时间】:2019-04-09 04:56:08
【问题描述】:
考虑一个无聊的游戏,白色和红色方块按如下顺序排列:
(开始 w w w w w w r r w w w w r w r w r w 结束)
w = 白色。 r = 红色。
有 3 个按钮。 绿色按钮:移动 5 步。 黄色按钮:移动 3 步。 蓝色按钮:移动 3 步。
游戏规则: - 如果玩家落在红色方块上输了。 - 第一个玩家完成游戏获胜。 - 允许在白色方块上着陆。
贪心算法:
x = 0
steps = 0
stop = false
while (....)
if a[x+5] is white then
push the green buttton and x= x+5, steps++
if a[x+3] is white then
push the yellow buttton and x= x+3, steps++
if a[x+2] is white then
push the blue buttton and x= x+2, steps++
else stop = true
必需:赢得比赛的最少步数。
按照上面的贪心算法,解将是 552225,而最优解是 33555。
我的问题是如何应用动态算法找到最优解?
【问题讨论】: