第三個月開始生兔子是 f(n) = f(n-1) +f(n-2)
低四個月開始生兔子是f(n) = f(n-1) + f(n-3)
低四個月開始生兔子是f(n) = f(n-1) + f(n-3)
2021-06-30
"""
爬n級樓梯的方式
"""
l = []
def up_stair(n, process=""):
if n == 1:
l.append(process + ">1")
if n == 2:
l.append(process + ">1>1")
l.append(process + ">2")
if n > 2:
up_stair(n - 1, process + ">1")
up_stair(n - 2, process + ">2")
up_stair(2)
print(len(l))
爬n級樓梯的方式
"""
l = []
def up_stair(n, process=""):
if n == 1:
l.append(process + ">1")
if n == 2:
l.append(process + ">1>1")
l.append(process + ">2")
if n > 2:
up_stair(n - 1, process + ">1")
up_stair(n - 2, process + ">2")
up_stair(2)
print(len(l))
2021-01-05
def search(datas):
if not datas:
print(arranges)
global total
total += 1
else:
for data in datas:
arranges.append(data)
next_datas = datas[:]
next_datas.remove(data)
search(next_datas)
arranges.pop()
if not datas:
print(arranges)
global total
total += 1
else:
for data in datas:
arranges.append(data)
next_datas = datas[:]
next_datas.remove(data)
search(next_datas)
arranges.pop()
2020-12-10
# 判斷/方向
for i in range(x):
if y + 1 + i <= 7:
if board[x - 1 - i][y + 1 + i] == 1: # 不判斷當(dāng)前點
return False
# 判斷\方向
for i in range(x):
if y - 1 - i >= 0:
if board[x - 1 - i][y - 1 - i] == 1: # 不判斷當(dāng)前點
return False
for i in range(x):
if y + 1 + i <= 7:
if board[x - 1 - i][y + 1 + i] == 1: # 不判斷當(dāng)前點
return False
# 判斷\方向
for i in range(x):
if y - 1 - i >= 0:
if board[x - 1 - i][y - 1 - i] == 1: # 不判斷當(dāng)前點
return False
2020-10-16
def move(index,start,mid,end):
if index == 1:
print(f'{start}-->{end}')
return
move(index-1,start,end,mid)
print(f'{start}-->{end}')
move(index-1,mid,start,end)
最后這個應(yīng)該是move(index-1,mid,start,end)通過 mid移動到end 通過start這個柱子吧
if index == 1:
print(f'{start}-->{end}')
return
move(index-1,start,end,mid)
print(f'{start}-->{end}')
move(index-1,mid,start,end)
最后這個應(yīng)該是move(index-1,mid,start,end)通過 mid移動到end 通過start這個柱子吧
2020-08-12
算法真神奇,幾行代碼就可以實現(xiàn)這么復(fù)雜的計算過程,有時候關(guān)注宏觀的計算步驟就好了,在意太多細(xì)節(jié)反而把自己搞暈
2020-06-10