欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1550B.Maximum Cost Deletion
Maximum Cost Deletion
You are given a string of length consisting only of the characters 0 and 1.
You perform the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue the remaining two parts together (any of them can be empty) in the same order. For example, if you erase the substring 111 from the string 111110, you will get the string 110. When you delete a substring of length , you get points.
Your task is to calculate the maximum number of points that you can score in total, if you have to make the given string empty.
Input
The first line contains a single integer () — the number of testcases.
The first line of each testcase contains three integers , and () — the length of the string and the parameters and .
The second line contains the string . The string consists only of the characters 0 and 1.
Output
For each testcase, print a single integer — the maximum number of points that you can score.
Note
In the first example, it is enough to delete the entire string, then we will get points.
In the second example, if we delete characters one by one, then for each deleted character we will get points, i. e. points in total.
In the third example, we can delete the substring 00 from the string 100111, we get points, and the string will be equal to 1111, removing it entirely we get points. In total, we got points for operations.
Samples
3
3 2 0
000
5 -2 5
11001
6 1 -4
100111
6
15
-2
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |