CF1621F.Strange Instructions

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Dasha has 1010010^{100} coins. Recently, she found a binary string ss of length nn and some operations that allows to change this string (she can do each operation any number of times):

  1. Replace substring 00 of ss by 0 and receive aa coins.
  2. Replace substring 11 of ss by 1 and receive bb coins.
  3. Remove 0 from any position in ss and pay cc 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 11-33 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.

达莎有 1010010^{100} 枚硬币。最近,她发现了一个长度为 nn 的二进制字符串 ss,以及若干可用来修改该字符串的操作(每种操作均可执行任意多次):

  1. 将 ss 中的子串 00 替换为 0,并获得 aa 枚硬币;
  2. 将 ss 中的子串 11 替换为 1,并获得 bb 枚硬币;
  3. 删除 ss 中任意位置的一个 0,并支付 cc 枚硬币。

此外,达莎在执行这些操作时必须遵守如下规则:

  • 禁止连续两次执行奇偶性相同的操作。操作按上述顺序编号为整数 11–33,其奇偶性即对应编号的奇偶性(即操作 1 和 3 为奇数操作,操作 2 为偶数操作)。

请计算:达莎在遵守该规则的前提下,通过执行这些操作所能获得的最大收益(即最终硬币数减去初始硬币数)。

输入格式

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains four integers nn, aa, bb, cc (1≤n≤105,1≤a,b,c≤1091 \leq n \leq 10^5, 1 \leq a, b, c \leq 10^9).

The second line of each test case contains a binary string ss of length nn.

It is guaranteed that the total sum of nn over all test cases doesn't exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。

每个测试用例的第一行包含四个整数 nn、aa、bb、cc(1≤n≤1051 \leq n \leq 10^5,1≤a,b,c≤1091 \leq a, b, c \leq 10^9)。

每个测试用例的第二行包含一个长度为 nn 的二进制字符串 ss。

保证所有测试用例中 nn 的总和不超过 2⋅1052 \cdot 10^5。

输出格式

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 →\rightarrow 0101 →\rightarrow 011 →\rightarrow 01. This sequence of operations consists of operations 22, 33 and 22 in this order. It satisfies all rules and gives profit 33. It can be shown that it is impossible to achieve higher profit in this test case, so the answer is 33.

In the second test case one of the optimal sequences of operations is 110001 →\rightarrow 11001 →\rightarrow 1001 →\rightarrow 101.

In the third test case one of the optimal sequences of operations is 011110 →\rightarrow 01110 →\rightarrow 1110 →\rightarrow 110 →\rightarrow 11 →\rightarrow 1.

在第一个测试用例中,一种最优的操作序列是:01101 →\rightarrow 0101 →\rightarrow 011 →\rightarrow 01。该操作序列依次执行操作 22、33 和 22。它满足所有规则,获得利润为 33。可以证明,在该测试用例中无法获得更高的利润,因此答案为 33。

在第二个测试用例中,一种最优的操作序列是:110001 →\rightarrow 11001 →\rightarrow 1001 →\rightarrow 101。

在第三个测试用例中,一种最优的操作序列是:011110 →\rightarrow 01110 →\rightarrow 1110 →\rightarrow 110 →\rightarrow 11 →\rightarrow 1。

输入解题思路,AI测评打分。不知道怎么写?

首页