def Havel(arr)
n = len(arr)
for i in range(n):
seq = sorted(arr, reverse=True)
if seq[0] >= n-i:
return False
for j in range(1, seq[0]+1):
seq[j] -= 1
if seq[j] < 0:
return False
arr = seq[1:]
return True
将上述序列作为输入
kases = [
[3,4,4,3,1],
[4,2,2,1,1],
[3,3,3,2,2],
[3,4,3,2,1]
]
for kase in kases:
if Havel(kase):
print(kase)