CF1440A.Buy the String

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

You are given four integers nn, c0c_0, c1c_1 and hh and a binary string ss of length nn.

A binary string is a string consisting of characters 00 and 11.

You can change any character of the string ss (the string should be still binary after the change). You should pay hh coins for each change.

After some changes (possibly zero) you want to buy the string. To buy the string you should buy all its characters. To buy the character 00 you should pay c0c_0 coins, to buy the character 11 you should pay c1c_1 coins.

Find the minimum number of coins needed to buy the string.

给你四个整数 nn、c0c_0、c1c_1 和 hh,以及一个长度为 nn 的二进制字符串 ss。

二进制字符串是指仅由字符 00 和 11 组成的字符串。

你可以修改字符串 ss 中的任意字符(修改后字符串仍需保持为二进制字符串)。每次修改需花费 hh 枚硬币。

在进行若干次(可能为零次)修改之后,你需要购买该字符串。购买字符串意味着购买其所有字符:购买字符 00 需花费 c0c_0 枚硬币,购买字符 11 需花费 c1c_1 枚硬币。

求购买该字符串所需的最少硬币数量。

输入格式

The first line contains a single integer tt (1≤t≤101 \leq t \leq 10) — the number of test cases. Next 2t2t lines contain descriptions of test cases.

The first line of the description of each test case contains four integers nn, c0c_{0}, c1c_{1}, hh (1≤n,c0,c1,h≤10001 \leq n, c_{0}, c_{1}, h \leq 1000).

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

第一行包含一个整数 tt(1≤t≤101 \leq t \leq 10),表示测试用例的数量。接下来的 2t2t 行包含各测试用例的描述。

每个测试用例描述的第一行包含四个整数 nn、c0c_{0}、c1c_{1}、hh(1≤n,c0,c1,h≤10001 \leq n, c_{0}, c_{1}, h \leq 1000)。

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

输出格式

For each test case print a single integer — the minimum number of coins needed to buy the string.

对于每个测试用例,输出一个整数——购买该字符串所需的最少硬币数量。

输入输出样例

  • 输入#1

    6
    3 1 1 1
    100
    5 10 100 1
    01010
    5 10 1 1
    11111
    5 1 10 1
    11111
    12 2 1 10
    101110110101
    2 100 1 10
    00

    输出#1

    3
    52
    5
    10
    16
    22

说明/提示

In the first test case, you can buy all characters and pay 33 coins, because both characters 00 and 11 costs 11 coin.

In the second test case, you can firstly change 22-nd and 44-th symbols of the string from 11 to 00 and pay 22 coins for that. Your string will be 0000000000. After that, you can buy the string and pay 5⋅10=505 \cdot 10 = 50 coins for that. The total number of coins paid will be 2+50=522 + 50 = 52.

在第一个测试用例中,你可以购买所有字符,花费 33 枚硬币,因为字符 00 和 11 的价格均为 11 枚硬币。

在第二个测试用例中,你可以首先将字符串的第 22 个和第 44 个字符由 11 改为 00,为此花费 22 枚硬币。此时你的字符串变为 0000000000。之后,你可以购买该字符串,为此花费 5⋅10=505 \cdot 10 = 50 枚硬币。总共花费的硬币数为 2+50=522 + 50 = 52。

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

首页