第三個(gè)月開始生兔子是 f(n) = f(n-1) +f(n-2)
低四個(gè)月開始生兔子是f(n) = f(n-1) + f(n-3)
低四個(gè)月開始生兔子是f(n) = f(n-1) + f(n-3)
2021-06-30
"""
爬n級(jí)樓梯的方式
"""
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級(jí)樓梯的方式
"""
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
老師講解的非常通俗易懂,總算是理解動(dòng)態(tài)規(guī)劃了,謝謝老師。
2020-11-30
最新回答 / 慕仰1355216
是的,這一點(diǎn)老師寫錯(cuò)了,但是推演到下一個(gè)寫法的時(shí)候,這個(gè)錯(cuò)誤就不重要了,因?yàn)橹虚g階段的寫法本來就是過度的。
2020-11-19
# 判斷/方向
for i in range(x):
if y + 1 + i <= 7:
if board[x - 1 - i][y + 1 + i] == 1: # 不判斷當(dāng)前點(diǎn)
return False
# 判斷\方向
for i in range(x):
if y - 1 - i >= 0:
if board[x - 1 - i][y - 1 - i] == 1: # 不判斷當(dāng)前點(diǎn)
return False
for i in range(x):
if y + 1 + i <= 7:
if board[x - 1 - i][y + 1 + i] == 1: # 不判斷當(dāng)前點(diǎn)
return False
# 判斷\方向
for i in range(x):
if y - 1 - i >= 0:
if board[x - 1 - i][y - 1 - i] == 1: # 不判斷當(dāng)前點(diǎn)
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)
最后這個(gè)應(yīng)該是move(index-1,mid,start,end)通過 mid移動(dòng)到end 通過start這個(gè)柱子吧
if index == 1:
print(f'{start}-->{end}')
return
move(index-1,start,end,mid)
print(f'{start}-->{end}')
move(index-1,mid,start,end)
最后這個(gè)應(yīng)該是move(index-1,mid,start,end)通過 mid移動(dòng)到end 通過start這個(gè)柱子吧
2020-08-12