#P9653. 『GROI-R2』 不空白的画布
『GROI-R2』 不空白的画布
Problem Description
As we all know, after Alice hid away, Tenniel sat in front of a blank canvas, picked up a piece of charcoal, and began to draw.
But now the canvas is no longer blank, because the current scenery is already on it. Suppose the canvas length is . The color at each unit position can be represented by a positive integer in the range .
Tenniel still wants to draw the teacup he has knocked over. Each time he draws, he may choose any position on the canvas and repaint the color at that position into any positive integer in .
In the end, we know this painting has memory. Define the number of memory fragments left on the painting as the number of consecutive blocks of the same color. Now Tenniel wants to know: given an upper limit on the number of times he can repaint, what is the maximum possible number of memory fragments on the painting?
Formal statement
You have consecutive cells. Each cell has an initial color , and it is guaranteed that .
You may perform at most operations. Each operation changes the color of one cell, and the new color must still be in .
We call a maximal consecutive segment of the same color one block. You need to find the maximum number of blocks after at most operations.
Input Format
This problem has multiple test cases.
The first line contains a positive integer , denoting the number of test cases.
For each test case, the first line contains three positive integers , representing the canvas length, the upper limit of Tenniel’s painting operations, and the range of colors.
The second line contains an integer sequence of length , representing the initial color at each position on the canvas.
Output Format
For each test case, output one positive integer per line, representing the maximum possible number of memory fragments.
2
3 1 3
2 2 2
5 2 4
2 2 2 2 3
3
5
Hint
Sample explanation
For the first test case, Tenniel can repaint the second position from left to right to color , obtaining . The number of blocks is .
For the second test case, Tenniel can repaint the second position from left to right to color , and repaint the third position from left to right to color , obtaining . The number of blocks is .
Constraints
This problem uses bundled testdata.
| Score | ||||
|---|---|---|---|---|
For of the testdata, , , , , and .
Translated by ChatGPT 5