1749. Colored stones

单点时限: 2.0 sec

内存限制: 256 MB

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?

输入格式

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.

输出格式

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

样例

Input
10 3
2 1 2 2 1 1 3 1 3 3
0 0
Output
2
Hint
In the above example, an optimal solution is achieved by removing the 2nd stone and the 7th stone, leaving three “2” stones, three “1” stones, and two “3” stones. Other solutions may be possible.

1 人解决,3 人已尝试。

1 份提交通过,共有 3 份提交。

9.9 EMB 奖励。

创建: 16 年,6 月前.

修改: 6 年,8 月前.

最后提交: 9 月,1 周前.

来源: Stanford Local 2005

题目标签