题目:
☐☐☐+☐☐☐=☐☐☐
填入数字1-9,有多少种组合
Python解法:
count=0 def dfs(n,alist): if n==9: if alist[0]*100+alist[1]*10+alist[2]+alist[3]*100+alist[4]*10+alist[5]==alist[6]*100+alist[7]*10+alist[8]: print(alist) global count count+=1 for i in range(9): if i not in alist: alist.append(i) dfs(n+1,alist) alist.pop() dfs(0,[]) print(count)