codeforces
思路:动态更新每个格子的最小值,最后查找能跳出去的几个格子的最小值即可(注意最后比较时格子长度不能短于p)
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+5;
int arr[N];
int dp[N];
void solve(){
int len,p,k;
cin>>len>>p>>k;
string ff =" ";
string s;cin>>s;
ff+=s;
int x,y;
cin>>x>>y;
if(ff[p]=='0'){
dp[p]=x;
}
else
{
dp[p]=0;
}
for(int i =p+1;i<ff.size();i++){
if(i-k>=p){
dp[i] = min(dp[i-k],(i-p)*y);
}
else{
dp[i] =(i-p)*y;
}
if(ff[i]=='0')
dp[i]+=x;
}
int ans =1e9;
// for(int i=p;i<=len;i++){
// cout<<dp[i]<<" ";
// }
// cout<<endl;
for(int i =max(len-k+1,p);i<=len;i++){
ans = min(ans,dp[i]);
}
cout<<ans<<endl;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int __=1;
cin>>__;
while (__--) {
solve();
}
}