https://codeforces.com/contest/1440/problem/A
The meaning of the question: 0 and 1, taking 0 and 1 have their own costs, and there is a common cost H that converts 0 into 1 and 1 into 0.
Idea: Greedy, if it can be transformed, it must be the best, otherwise it will not be transformed. Consider the two fully transformed cases and the unchanged case. Take the best value.
#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e4;
typedef long long LL;
char str[maxn];
int main(void)
{
cin.tie(0);std::ios::sync_with_stdio(false);
LL t;cin>>t;
while(t--)
{
LL n,c0,c1,h;cin>>n>>c0>>c1>>h;
LL num0=0;LL num1=0;
cin>>(str+1);
LL len=strlen(str+1);
for(LL i=1;i<=len;i++){
if(str[i]=='0') num0++;
else num1++;
}
LL sum1=num0*c0+num1*c1;
LL sum2=h*num0+num0*c1+num1*c1;
LL sum3=h*num1+num1*c0+num0*c0;
cout<<min(sum1,min(sum2,sum3))<<endl;
}
return 0;
}