CF2172L.Maximum Color Segment
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a rope n units long, where each unit is painted either red or black. The rope can be represented as a string of length n consisting of characters R (red) and B (black). You are also given two integers m and k.
You may perform the following operation at most m times (possibly, zero times):
- Choose any contiguous substring∗ of the rope of length exactly k.
- Flip the color of every unit in the substring: each R becomes B, and each B becomes R.
For example, consider the rope RRRRBRRR with k=4. If you choose the 3-rd to 6-th characters (RRRRBRRR), then after flipping, the rope becomes RRBBRBRR.
Define the number of color segments as the smallest number of contiguous segments into which the rope can be divided so that each segment consists of units of a single color. For instance, the rope RRBRRRBB has 4 color segments: RR, B, RRR, and BB.
Your task is to determine the maximum possible number of color segments after performing at most m operations.
∗A string t is a substring of a string s if t can be obtained from s by the deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
你有一根长度为 n 的绳子,其中每个单位长度的绳子被涂成红色或黑色。该绳子可表示为一个长度为 n 的字符串,由字符 R(红色)和 B(黑色)组成。你还给定两个整数 m 和 k。
你最多可以执行以下操作 m 次(也可以不执行):
- 选择绳子中任意一个连续子串∗,其长度恰好为 k;
- 将该子串中每个单位的颜色翻转:每个 R 变为 B,每个 B 变为 R。
例如,考虑绳子 RRRRBRRR 且 k=4。若你选择第 3 至第 6 个字符(即 RRRRBRRR 中的 RRBR),翻转后绳子变为 RRBBRBRR。
定义颜色段的数量为:将绳子划分为最少数量的连续段,使得每一段内的所有单位颜色相同。例如,绳子 RRBRRRBB 有 4 个颜色段:RR、B、RRR 和 BB。
你的任务是:在最多执行 m 次操作的前提下,求出颜色段数量的最大可能值。
∗ 字符串 t 是字符串 s 的子串,当且仅当 t 可通过从 s 的开头删除若干(可能为零或全部)字符,并从结尾删除若干(可能为零或全部)字符而得到。
输入格式
The first line contains three integers n, m, and k, representing the length of the rope, the maximum number of operations allowed, and the length of each operation's flip window, respectively.
The second line contains a string of length n consisting only of the characters R and B, representing the initial content of the rope.
- 1≤n≤3000
- 0≤m≤3000
- 1≤k≤n
第一行包含三个整数 n、m 和 k,分别表示绳子的长度、允许的最大操作次数以及每次翻转操作所作用的窗口长度。
第二行包含一个长度为 n 的字符串,仅由字符 R 和 B 组成,表示绳子的初始状态。
- 1≤n≤3000
- 0≤m≤3000
- 1≤k≤n
输出格式
Output an integer in a single line, representing the maximum possible number of color segments after performing at most m operations.
在一行中输出一个整数,表示最多进行 m 次操作后所能得到的颜色段的最大数量。
输入输出样例
输入#1
5 4 3 RRBRR
输出#1
5
输入#2
10 3 3 RRRRBBRRRB
输出#2
8
输入#3
7 4 7 RRBRBBR
输出#3
5
输入解题思路,AI测评打分。不知道怎么写?