QOJ.ac

QOJ

Time Limit: 2.0 s Memory Limit: 256 MB Total points: 100 Hackable ✓

#15404. Maximum Color Segment

统计

给定一根长度为 $n$ 的绳子,其中每个单位被涂成红色或黑色。这根绳子可以用一个长度为 $n$、由字符 R(红色)和 B(黑色)组成的字符串来表示。同时给定两个整数 $m$ 和 $k$。

你可以执行以下操作至多 $m$ 次(也可以执行零次):

  • 选择绳子中任意一个长度恰好为 $k$ 的连续子串。
  • 翻转该子串中每个单位的颜色:每个 R 变为 B,每个 B 变为 R。

例如,考虑绳子 RRRRBRRR,其中 $k = 4$。如果你选择第 3 到第 6 个字符(RRRRBRRR),翻转后绳子变为 RRBBRBRR。

将颜色段的数量定义为将绳子划分为由单一颜色组成的连续段的最小段数。例如,绳子 RRBRRRBB 有 4 个颜色段:RR、B、RRR 和 BB。

你的任务是确定在执行至多 $m$ 次操作后,颜色段数量的最大可能值。

输入格式

第一行包含三个整数 $n$、$m$ 和 $k$,分别表示绳子的长度、允许的最大操作次数以及每次操作翻转窗口的长度。

第二行包含一个长度为 $n$、仅由字符 R 和 B 组成的字符串,表示绳子的初始状态。

  • $1 \le n \le 3000$
  • $0 \le m \le 3000$
  • $1 \le k \le n$

输出格式

输出一行一个整数,表示执行至多 $m$ 次操作后,颜色段数量的最大可能值。

样例

输入 1

5 4 3
RRBRR

输出 1

5

输入 2

10 3 3
RRRRBBRRRB

输出 2

8

输入 3

7 4 7
RRBRBBR

输出 3

5

*字符串 $t$ 是字符串 $s$ 的子串,如果 $t$ 可以通过从 $s$ 的开头删除若干(可能为零或全部)字符,并从结尾删除若干(可能为零或全部)字符得到。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.