mirror of
https://github.com/krahets/hello-algo.git
synced 2026-11-02 11:15:19 +08:00
* Retranslate the complete Japanese online edition from Chinese * Fit Japanese homepage labels and localize heading permalinks * Point Japanese contribution instructions to the Japanese preview * Replace locale conditionals with multilingual UI tables
29 lines
595 B
Python
29 lines
595 B
Python
"""
|
|
File: climbing_stairs_dfs.py
|
|
Created Time: 2023-06-30
|
|
Author: krahets ([email protected])
|
|
"""
|
|
|
|
|
|
def dfs(i: int) -> int:
|
|
"""探索"""
|
|
# dp[1] と dp[2] は既知なので、その値を返す
|
|
if i == 1 or i == 2:
|
|
return i
|
|
# dp[i] = dp[i-1] + dp[i-2]
|
|
count = dfs(i - 1) + dfs(i - 2)
|
|
return count
|
|
|
|
|
|
def climbing_stairs_dfs(n: int) -> int:
|
|
"""階段の上り方:探索"""
|
|
return dfs(n)
|
|
|
|
|
|
"""実行用コード"""
|
|
if __name__ == "__main__":
|
|
n = 9
|
|
|
|
res = climbing_stairs_dfs(n)
|
|
print(f"{n} 段の階段を上る方法は全部で {res} 通り")
|