当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

2978:Colored stones

题目描述

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.

输入样例
10 3
2 1 2 2 1 1 3 1 3 3
0 0
输出样例
2
提示

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.


该题目是Virtual Judge题目,来自 北京大学POJ

题目来源 Stanford Local 2005

源链接: POJ-2978

最后修改于 2020-10-29T06:49:00+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 65536