0分全TLE!why!
查看原帖
0分全TLE!why!
1674226
markwu1楼主2025/7/24 19:06
#include<bits/stdc++.h>
using namespace std;
long long m=0;
long long n=0;
long long a[28]={0};
long long dp[100008]={0};
string s="";
long long calc(int start,int end){
	string str=s.substr(start,end-start+1);
	long long cnt=0;
	while(str.find("abc")!=string::npos){
		cnt++;
		str=str.erase(str.find("abc"),3);
	}
	return a[cnt];
}
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	cin>>m>>s;
	for(int i=0;i<=m-1;i++){
		for(int j=i-1;j>=0;j--){
			dp[i]=max(dp[i],dp[j]+calc(j+1,i));
			//cout<<j<<' '<<calc(j+1,i)<<endl;
		}
	//	cout<<dp[i]<<endl<<endl;
	}
	cout<<dp[m-1];
	return 0;
}
2025/7/24 19:06
加载中...