B. Maximum Cost Deletion
题意:t 组数据 输入n 和 a 和 b 输入n个字符的字符串 此字符串只含有0 1, 求 a*x+b的最大值 x指每次删除字符串中相同的1或者0 把字符串字符删完为止。
题解:无论如何 a都会乘以n ,因此只用看 n 个b相加大 还是 x段b相加大。
代码:
#include<iostream>
#include<string>
using namespace std;
int n, a, b;
string ch;
void judge()
{
int cnt = 1;
for (int i = 0; i < ch.size() - 1; i++)
if (ch[i] != ch[i + 1])cnt++;
cout << a * n + max(b * n, b * (cnt / 2 + 1)) << endl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t; cin >> t;
while (t--)
{
cin >> n >> a >> b >> ch;
judge();
}
return 0;
}