A
思路:
判断三种情况:
- 不需要改变
- 0->1
- 1->0
代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
typedef long long LL;
int test=1;
int n,c0,c1,h;
string s;
int main()
{
scanf("%d", &test);
while(test--)
{
cin >> n >> c0 >> c1 >> h;
cin >> s;
int x=0,y=0;
for(int i=0;i<n;i++)
{
if(s[i]=='0')
x++;
else
y++;
}
if(c0==c1)
{
cout << n * c0 << '\n';
}
else if(abs(c0-c1) > h)
{
if(c0>c1)
cout << n * c1 + h * x << '\n';
else
cout << n * c0 + h * y << '\n';
}
else
cout << c0 * x + c1 * y << '\n';
continue;
}
return 0;
}