AcWing 3770. 最小消耗
原题链接
简单
作者:
牛奶小柒Luke
,
2021-07-17 20:23:28
,
所有人可见
,
阅读 290
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
const int N = 1010;
int n,a,b,c;
string s;
int main()
{
int T;
cin >> T;
while(T--){
cin >> n >> a >> b >> c;
cin >> s;
int cnt1 = 0,cnt2 = 0;
for (int i = 0; i < n; i ++ ){
if(s[i] == '0') cnt1++;
else cnt2++;
}
int res = 0;
if(abs(a - b) > c){
if(a > b) res = cnt1 * c + (cnt1 + cnt2) * b;
else res = cnt2 * c + (cnt1 + cnt2) * a;
}else res = cnt1 * a + cnt2 * b;
cout << res << endl;
}
return 0;
}