算法题:Maximum Cost Deletion(题目+思路+代码+注释)

算法题:Maximum Cost Deletion(题目+思路+代码+注释)
  • 题目

B. Maximum Cost Deletion

time limit per test: 2 seconds

memory limit per test: 256 megabytes

input: standard input

output: standard output

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⋅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.

Input

The first line contains a single integer t (1≤t≤20001≤t≤2000) — the number of testcases.

The first line of each testcase contains three integers n, a and b (1≤n≤100;−100≤a,b≤1001≤n≤100;−100≤a,b≤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.

Output

For each testcase, print a single integer — the maximum number of points that you can score.

Example

input

Copy

3
3 2 0
000
5 -2 5
11001
6 1 -4
100111

output

Copy

6
15
-2

Note

In the first example, it is enough to delete the entire string, then we will get 2⋅3+0=62⋅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)⋅1+5=3 points, i. e. 1515 points in total.

In the third example, we can delete

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值