最小消耗

题目 最小消耗

faa2820fff1d7734113a4723542ae987-faa2820f

思路分析

dc3a3379009e9903c5b6281375eab6f1_720-34bdad8d

代码实现

#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(){
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int T;cin>>T;
    while(T--){
        int n,a,b,c;cin>>n>>a>>b>>c;
        string str;cin>>str;
        int total=0;
        for(auto ch:str){
            if(ch=='0')  total+=min(a,b+c);
            else if(ch=='1') total+=min(b,a+c);
        }
        cout<<total<<endl;
    }

    return 0;
}

同类题型

视频讲解


⬅️ 排队打水 🏠 00-刷题理模型 ➡️ 耍杂技的牛