Problem B
Cutting Proteins
Languages
en
sv
Your friend Björn has recently started a large chemistry experiment with the goal of creating a secret protein. All proteins are described with strings of letters from a-z, for example, bcaa and hello. He needs to create several so-called pure proteins. These are proteins consisting of copies of the same letter. To do this, he has microscopic scissors called CRISPR. With these, he can remove up to $K$ adjacent letters. In other words, he can choose an interval with up to $K$ letters to cut out. If a protein is divided into two parts when it is cut, these parts will then be joined together where they were cut.
Since he is very lazy, he wants your help to write a program that calculates the minimum number of times he needs to cut a specific protein to make it pure. Note that the protein must not become an empty string, because in that case it can no longer be used for chemistry.
Input
The first line of input contains a string $P$ ($1 \leq |P| \leq 50$), the protein that Björn wants to make pure. $P$ only consists of characters from a-z.
The next line contains the integer $K$ ($1 \leq K \leq |P|$), the number of characters that Björn can remove in each cut.
Output
Print an integer: the smallest number of cuts Björn needs to make in order to make the protein pure.
Points
Your solution will be tested on several test case groups. To get the points for a group, it must pass all the test cases in the group.
Group |
Point value |
Constraints |
$1$ |
$20$ |
$K=1$ |
$2$ |
$20$ |
The protein only consists of the characters a and b. |
$3$ |
$60$ |
No additional constraints. |
Explanation of samples
Sample $1$: one optimal
way is to first cut the characters pe. This results in the string exemlfall.
We can then cut away fa, resulting in
exemlll.
Finally, we cut away exem and are
left with lll, a pure protein.
The picture shows the solution to sample 2. If we cut away
all b in the way that the picture
describes, the protein becomes pure in two cut.
Sample Input 1 | Sample Output 1 |
---|---|
exempelfall 4 |
3 |
Sample Input 2 | Sample Output 2 |
---|---|
aabbabbba 3 |
2 |