0分求助
查看原帖
0分求助
556838
Cc_Sleep楼主2024/10/19 10:49
#include <bits/stdc++.h>
#define int long long
#define LIMIT 114514
using namespace std;

const int N=2e5+5;
int n,m,res,ans;
int a[25],f[N];
string st;

signed main(){
	cin.tie(0)->sync_with_stdio(0);
	cin>>n;
	for(int i=1; i<=n; i++){
		cin>>a[i];
		for(int j=i; j<=LIMIT; j++)
			f[j]=max(f[j],f[j-i]+a[i]);
	}
	cin>>m>>st;
	st="#"+st;
	for(int i=1; i<=m; i++){
		if(st[i]=='a'&&st[i+1]=='b'&&st[i+2]=='c'){
			i+=2;
			res++;
		}
		else{
			ans+=f[res];
			res=0;
		}
	}
	cout<<ans<<"\n";
	return 0;
}
2024/10/19 10:49
加载中...