Advertisement
DimaT1

613_n**2

Sep 7th, 2016
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. from collections import deque
  2.  
  3.  
  4. ain = list(map(int, input().split()))
  5.  
  6. d = []
  7. p = []
  8.  
  9.  
  10. for i in range(len(ain)):
  11.   d.append(1)
  12.   p.append(-1)
  13.   for j in range(i):
  14.     if ain[i] > ain[j]:
  15.       if d[j] >= d[i]:
  16.         d[i] = d[j] + 1
  17.         p[i] = j
  18.        
  19. m = max(d)
  20. print(m)
  21.  
  22. c = d.index(m)
  23. st = deque()
  24. st.append(c)
  25. while(c != -1):
  26.   c = p[c]
  27.   st.append(c)
  28. st.pop()
  29.  
  30. while len(st) != 0:
  31.   c = st.pop()
  32.   print(ain[c],  = ' ')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement