CF1550B.Maximum Cost Deletion

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a string ss of length nn 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 ll , you get al+ba \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 tt ( 1t20001 \le t \le 2000 ) — the number of testcases.

The first line of each testcase contains three integers nn , aa and bb ( 1n100;100a,b1001 \le n \le 100; -100 \le a, b \le 100 ) — the length of the string ss and the parameters aa and bb .

The second line contains the string ss . The string ss 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 23+0=62 \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)1+5=3(-2) \cdot 1 + 5 = 3 points, i. e. 1515 points in total.

In the third example, we can delete the substring 00 from the string 100111, we get 12+(4)=21 \cdot 2 + (-4) = -2 points, and the string will be equal to 1111, removing it entirely we get 14+(4)=01 \cdot 4 + (-4) = 0 points. In total, we got 2-2 points for 22 operations.

首页