A14427 | Maximum Cost Deletion
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a string $s$ of length $n$ 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 $l$ , you get $a \cdot l + b$ 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.
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 $l$ , you get $a \cdot l + b$ 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.
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 2000$ ) — the number of testcases.
The first line of each testcase contains three integers $n$ , $a$ and $b$ ( $1 \le n \le 100; -100 \le a, b \le 100$ ) — the length of the string $s$ and the parameters $a$ and $b$ .
The second line contains the string $s$ . The string $s$ consists only of the characters 0 and 1.
The first line of each testcase contains three integers $n$ , $a$ and $b$ ( $1 \le n \le 100; -100 \le a, b \le 100$ ) — the length of the string $s$ and the parameters $a$ and $b$ .
The second line contains the string $s$ . The string $s$ consists only of the characters 0 and 1.
输出格式
For each testcase, print a single integer — the maximum number of points that you can score.
输入输出样例
输入 #1
3 3 2 0 000 5 -2 5 11001 6 1 -4 100111
输出 #1
6 15 -2
In the first example, it is enough to delete the entire string, then we will get $2 \cdot 3 + 0 = 6$ points.
In the second example, if we delete characters one by one, then for each deleted character we will get $(-2) \cdot 1 + 5 = 3$ points, i. e. $15$ points in total.
In the third example, we can delete the substring 00 from the string 100111, we get $1 \cdot 2 + (-4) = -2$ points, and the string will be equal to 1111, removing it entirely we get $1 \cdot 4 + (-4) = 0$ points. In total, we got $-2$ points for $2$ operations.
In the second example, if we delete characters one by one, then for each deleted character we will get $(-2) \cdot 1 + 5 = 3$ points, i. e. $15$ points in total.
In the third example, we can delete the substring 00 from the string 100111, we get $1 \cdot 2 + (-4) = -2$ points, and the string will be equal to 1111, removing it entirely we get $1 \cdot 4 + (-4) = 0$ points. In total, we got $-2$ points for $2$ operations.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted