D-4题解

#include <iostream>
using namespace std;
int main()
{
    int T;
    cin >> T;
    while (T--)
    {
        int n, c0, c1, h;
        cin >> n >> c0 >> c1 >> h;
        int num0 = 0, num1 = 0;
        char arr[n];
        for (int i = 0; i < n; i++)
        {
            cin >> arr[i];
            arr[i] == '1' ? num1++ : num0++;
        }
        int MinPrice = num0 * c0 + num1 * c1, MaxPrice = MinPrice;
        for (int i = 0; i <= num0; i++)
        {
            for (int j = 0; j <= num1; j++){
                int price = MaxPrice + i * (h - c0 + c1) + j * (h + c0 - c1);
                if(price < MinPrice && price > 0)
                    MinPrice = price;
                }
        }
        cout << MinPrice << endl;
    }
    return 0;
}

 

posted @ 2021-05-05 23:11  potentia1  阅读(78)  评论(0)    收藏  举报