最后两个点MLE了,求救!
光想着降时间复杂度了,好像还没法改,有没有大佬救救
ans_list = []
ans = 0
temp = {}
def son(s1,s2,s3):
s1,s2,s3 = tuple(s1),tuple(s2),tuple(s3)
global temp
global ans_list
global ans
if temp.get( (s1,s2,s3), None) == 1:
return
else:
temp[(s1,s2,s3)] = 1
if not s1 and not s2:
ans = ans + 1
ans_list.append(s1)
if s1:
son(s1[:-1], s2 + (s1[-1],), s3)
if s2:
son(s1, s2[:-1], s3 + (s2[-1],))
userInput = tuple(range(1,int(input())+1))
son(userInput, tuple(), tuple())
print(ans)