Logo
(追記) (追記ここまで)

7688번 - Colored stones 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 128 MB117763.636%

문제

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.

제한

예제 입력 1

10 3
2 1 2 2 1 1 3 1 3 3
0 0

예제 출력 1

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.

출처

University > Stanford Local ACM Programming Contest > SLPC 2005 6번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /