• [1332] Colored Sweet

  • 时间限制: 1000 ms 内存限制: 65535 K
  • 问题描述
  • You are given a row of N sweets each of which has one of N different colors. What is the minimum number of sweets you must remove so that no two sweets of one color are separated by a sweet of a different color?
  • 输入
  • The input test file will contain multiple test cases. Each input test case begins with a single line containing the integers N and K where 1 ≤ N ≤ 100 and 1 ≤ K ≤ 5. The next line contains N integers 1, …, N. each of which takes on values from the set {1, …, k}, representing the K different sweets colors. The end-of-file is marked by a test case with N = K = 0 and should not be processed.
  • 输出
  • For each input case, the program should the minimum number of sweets removed to satisfy the condition given in the problem.
  • 样例输入
  • 4 2
    1 2 2 1
    0 0 
  • 样例输出
  • 1
  • 提示
  • 来源
  • Minary
  • 操作

显示春菜