fork download
  1. # thg nào chép code tao méc admin
  2. a=int(input())
  3. b = [int(x) for x in input().split()]
  4. c = [b[0]]
  5. for i in b[1:]:
  6. if i!=c[-1]:
  7. c.append(i)
  8. a=len(c)
  9. dpa = []
  10. dpb = [0] * (a+1)
  11. for i in range(2,a+1):
  12. dp=[]
  13. for j in range(a-i+1):
  14. if c[j] == c[j+i-1]:
  15. dp.append(min(dpb[j], dpb[j+1], dpa[j+1])+1)
  16. else:
  17. dp.append(min(dpb[j], dpb[j+1])+1)
  18. dpa, dpb = dpb, dp
  19. print(dpb[0])
  20.  
Success #stdin #stdout 0.04s 9624KB
stdin
Standard input is empty
stdout
Standard output is empty