luogu#P5189. [COCI 2009/2010 #5] ZUMA

    ID: 4150 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>动态规划 DP2009区间 DPCOCI(克罗地亚)

[COCI 2009/2010 #5] ZUMA

Problem Description

Translated from COCI 2010.03.06 Task 4 “ZUMA”.

Mirko lines up NN marbles in a row, numbered 1N1 \ldots N in order. The color of marble ii is cic_i. He discovered that if he touches K\ge K consecutive marbles and all of them have the same color, magic will make these marbles disappear; after that, the marbles before these KK marbles become adjacent to the marbles after these KK marbles.

Mirko has many marbles at home. He wants to insert as few marbles as possible among these NN marbles (he may also insert marbles before the first marble or after the last marble) so that all of the original NN marbles plus all inserted marbles disappear.

Input Format

The first line contains N,KN, K.
The second line contains c1cNc_1 \ldots c_N.

Output Format

One line with one integer, the minimum number of marbles he needs to insert.

2 5
1 1
3
5 3
2 2 3 2 2
2
10 4
3 3 3 3 2 3 1 1 1 3
4

Hint

Constraints: 1N1001 \le N \le 100, 2K52 \le K \le 5, 1ci1001 \le c_i \le 100.

Translated by ChatGPT 5