同志们帮我看看Py递归暴搜哪里有问题?
查看原帖
同志们帮我看看Py递归暴搜哪里有问题?
707862
s_a_b_e_ryyds楼主2022/5/6 23:02
def hanshu(x,y):
    global cnt
    if [x,y] in ls:
        return None
    else:
        if x==a and y==b:
            cnt+=1
            return None
        elif x==a:
            hanshu(x,y+1)
        elif y==b:
            hanshu(x+1,y)
        else:
            hanshu(x+1,y)
            hanshu(x,y+1)
a,b,c,d=map(int,input().split())
ls=[[c-1,d-2],[c-2,d-1],[c+1,d-2],[c+2,d-1],[c+2,d+1],[c+1,d+2],[c-1,d+2],[c-2,d+1]]
cnt=0
hanshu(0,0)
print(cnt)
2022/5/6 23:02
加载中...