fork download
  1. #a n=10 k=2
  2. #b n=5 k=5
  3. #c n=10 k=10
  4. def partition(collection):
  5. if len(collection) == 1:
  6. yield [ collection ]
  7. return
  8.  
  9. first = collection[0]
  10. for smaller in partition(collection[1:]):
  11. # insert `first` in each of the subpartition's subsets
  12. for n, subset in enumerate(smaller):
  13. yield smaller[:n] + [[ first ] + subset] + smaller[n+1:]
  14. # put `first` in its own subset
  15. yield [ [ first ] ] + smaller
  16.  
  17. ans = 0
  18. something = list(range(1,11))
  19. alll = [p for p in partition(something)]
  20. for k in range(len(alll)):
  21. p = alll[k]
  22. aa = True
  23. if len(p)<=10:
  24. aa = True
  25. #print(p)
  26. for A in p:
  27. for B in p:
  28. if A!=B:
  29. for a in A:
  30. for c in A:
  31. for b in B:
  32. for d in B:
  33. if a<b<c<d:
  34. aa = False
  35. break
  36.  
  37. if aa:
  38. #print(p)
  39. ans+=1
  40. print(ans)
  41.  
Success #stdin #stdout 0.88s 102260KB
stdin
Standard input is empty
stdout
16796