Python超级玛丽过吊桥

360影视 2025-01-15 06:43 2

摘要:defcount_paths(N, bridge_length, K, traps):from functools import lru_cachetraps_set = set(traps)@lru_cache(maxsize=None)def dp(pos

defcount_paths(N, bridge_length, K, traps):from functools import lru_cachetraps_set = set(traps)@lru_cache(maxsize=None)def dp(position, life):if position == bridge_length + 1:return 1if life bridge_length + 1:continueif next_position in traps_set:total += dp(next_position, life - 1)else:total += dp(next_position, life)return totalreturn dp(0, N)# 输入处理N, bridge_length, K = map(int, input.split)traps = list(map(int, input.split))# 计算通关路线数量result = count_paths(N, bridge_length, K, traps)# 输出结果print(result)

来源:房居客人家

相关推荐