程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程解疑 >> x-Colored stones

x-Colored stones

編輯:編程解疑
Colored stones

Description

You are given a row of m stones each of which has one of k different colors. What is the minimum number of stones you must remove so that no two stones of one color are separated by a stone of a different color?

Input

The input test file will contain multiple test cases. Each input test case begins with a single line containing the integers m and k where 1 ≤ m ≤ 100 and 1 ≤ k ≤ 5. The next line contains m integers x1, …, xm each of which takes on values from the set {1, …, k}, representing the k different stone colors. The end-of-file is marked by a test case with m = k = 0 and should not be processed.

Output

For each input case, the program should the minimum number of stones removed to satisfy the condition given in the problem.

Sample Input

10 3
2 1 2 2 1 1 3 1 3 3
0 0
Sample Output

2

最佳回答:


http://aoxuemugualu.blog.163.com/blog/static/19150120220131024546879/

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved