Steps: 10000 Traceback (most recent call last): File "c:\Users\GamerNoTitle\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_trace_dispatch_regular.py", line 359, in __call__ is_stepping = pydev_step_cmd != -1 RecursionError: maximum recursion depth exceeded in comparison
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\GamerNoTitle\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "C:\Users\GamerNoTitle\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code exec(code, run_globals) File "c:\Users\GamerNoTitle\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\__main__.py", line 39, in <module> cli.main() File "c:\Users\GamerNoTitle\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main run() File "c:\Users\GamerNoTitle\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 284, in run_file runpy.run_path(target, run_name="__main__") File "c:\Users\GamerNoTitle\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path return _run_module_code(code, init_globals, run_name, File "c:\Users\GamerNoTitle\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code _run_code(code, mod_globals, init_globals, File "c:\Users\GamerNoTitle\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code exec(code, run_globals) File "c:\Users\GamerNoTitle\Desktop\Untitled.py", line 11, in <module> print(degrade(steps)) File "c:\Users\GamerNoTitle\Desktop\Untitled.py", line 8, in degrade memory[steps] = degrade(steps - 1) + degrade(steps - 2) File "c:\Users\GamerNoTitle\Desktop\Untitled.py", line 8, in degrade memory[steps] = degrade(steps - 1) + degrade(steps - 2) File "c:\Users\GamerNoTitle\Desktop\Untitled.py", line 8, in degrade memory[steps] = degrade(steps - 1) + degrade(steps - 2) [Previous line repeated 983 more times] File "c:\Users\GamerNoTitle\Desktop\Untitled.py", line 4, in degrade def degrade(steps): File "c:\Users\GamerNoTitle\.vscode\extensions\ms-python.python-2022.18.2\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_trace_dispatch_regular.py", line 469, in __call__ return None if event == 'call' else NO_FTRACE RecursionError: maximum recursion depth exceeded in comparison
DP算法
核心问题
合成问题
初始状态(就是i=1和i=2的状态)
计算后续状态
DP算法求解
还是上面那个跳台阶问题
1 2 3 4 5 6 7 8 9 10 11
steps = int(input('Steps: ')) # 台阶数
defdegrade(steps): result = [0] * (steps + 1) result[1], result[2] = 1, 2 for i inrange(3, steps+1): result[i] = result[i-1] + result[i-2] return result[steps]