我的代码是这样的,对于rows和cols> 15来说工作时间太长了,有没有更好的解决方案?问题链接:https ://projecteuler.net/problem=15
#!/usr/bin/env python
rows = 3
cols = 3
start_row = 0
start_col = 0
count = 0
def trace(row, col):
if row == rows and col == cols:
global count
count += 1
return
if col + 1 <= cols:
# print row, col
trace(row, col + 1)
if row + 1 <= rows:
# print row, col
trace(row + 1, col)
trace(start_row, start_col)
print count