开淘宝的店铺网站怎么做,短网址工具,广州网站策划公司,做logo的著名网站P 1135 奇怪的电梯 vis是个标记访问过还是没访问过。回溯使用。 find 如果找到位置标为真#xff0c;代表找到了 find为假时#xff0c;打印 -1 整体使用深度遍历#xff0c;向上#xff0c;向都试 注意越界#xff0c;电梯进入负的#xff0c;或高过楼层#xff0c;或此… P 1135 奇怪的电梯 vis是个标记访问过还是没访问过。回溯使用。 find 如果找到位置标为真代表找到了 find为假时打印 -1 整体使用深度遍历向上向都试 注意越界电梯进入负的或高过楼层或此位置已经被访问过或按的次数超过层数都是有问题的。 注意pos值与 A B值差1.即第1次是数组的第0个元素 N, A, B map(int, input().split( ))
l1 list(map(int, input().split( )))vis [0] * N
find Falsedef dfs(lis, pos, cnt):global findif pos 0 or pos len(lis) or cnt N or vis[pos] 1:return# print(pos, lis[pos])if pos B - 1:print(cnt)find Truereturnvis[pos] 1dfs(lis, pos l1[pos], cnt 1)dfs(lis, pos - l1[pos], cnt 1)vis[pos] 0dfs(l1, A - 1, 0)
if not find:print(-1)