CF1621F.Strange Instructions
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Dasha has 10100 coins. Recently, she found a binary string s of length n and some operations that allows to change this string (she can do each operation any number of times):
- Replace substring 00 of s by 0 and receive a coins.
- Replace substring 11 of s by 1 and receive b coins.
- Remove 0 from any position in s and pay c coins.
It turned out that while doing this operations Dasha should follow the rule:
- It is forbidden to do two operations with the same parity in a row. Operations are numbered by integers 1 - 3 in the order they are given above.
Please, calculate what is the maximum profit Dasha can get by doing these operations and following this rule.
输入格式
The first line contains a single integer t ( 1≤t≤104 ) — the number of test cases.
The first line of each test case contains four integers n , a , b , c ( 1≤n≤105,1≤a,b,c≤109 ).
The second line of each test case contains a binary string s of length n .
It is guaranteed that the total sum of n over all test cases doesn't exceed 2⋅105 .
输出格式
For each test case print the answer.
输入输出样例
输入#1
3 5 2 2 1 01101 6 4 3 5 110001 6 3 2 1 011110
输出#1
3 11 4
说明/提示
In the first test case one of the optimal sequences of operations is 01101 → 0101 → 011 → 01. This sequence of operations consists of operations 2 , 3 and 2 in this order. It satisfies all rules and gives profit 3 . It can be shown that it is impossible to achieve higher profit in this test case, so the answer is 3 .
In the second test case one of the optimal sequences of operations is 110001 → 11001 → 1001 → 101.
In the third test case one of the optimal sequences of operations is 011110 → 01110 → 1110 → 110 → 11 → 1.