fork download
  1. def fn():
  2. def maxim(level):
  3. max = 0
  4. for i in range(1, level):
  5. if stack[i] > max:
  6. max = stack[i]
  7. return max
  8. def display(level):
  9. global fout
  10. maxi = maxim(n+1)
  11. for i in range(1, maxi+1):
  12. for j in range(1, n+1):
  13. if stack[j] == i:
  14. print(j, end ="")
  15. #fout.write(str(j))
  16. print("*", end="")
  17. #fout.write("*")
  18. print()
  19. #fout.write("\n")
  20.  
  21. def solve(level):
  22. for i in range(1, maxim(level)+1+1):
  23. stack[level] = i
  24. if level == n:
  25. display(level)
  26. else:
  27. solve(level+1)
  28. global fout
  29. #fin = open("partitiimultime.in","r")
  30. #fout = open("partitiimultime.out","w")
  31. #n = int(fin.readline())
  32. n = int(input())
  33. stack = [0] * (n+1)
  34. stack[1] = 1
  35. solve(2)
  36. fn()
  37. # your code goes here
Success #stdin #stdout 0.03s 9740KB
stdin
5
stdout
12345*
1234*5*
1235*4*
123*45*
123*4*5*
1245*3*
124*35*
124*3*5*
125*34*
12*345*
12*34*5*
125*3*4*
12*35*4*
12*3*45*
12*3*4*5*
1345*2*
134*25*
134*2*5*
135*24*
13*245*
13*24*5*
135*2*4*
13*25*4*
13*2*45*
13*2*4*5*
145*23*
14*235*
14*23*5*
15*234*
1*2345*
1*234*5*
15*23*4*
1*235*4*
1*23*45*
1*23*4*5*
145*2*3*
14*25*3*
14*2*35*
14*2*3*5*
15*24*3*
1*245*3*
1*24*35*
1*24*3*5*
15*2*34*
1*25*34*
1*2*345*
1*2*34*5*
15*2*3*4*
1*25*3*4*
1*2*35*4*
1*2*3*45*
1*2*3*4*5*