参考程序:
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
int a[30];
string s;
int dp[N];
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
int m;
cin>>m;
cin>>s;
for(int i=1;i<=m;i++)
{
dp[i]=dp[i-1];
for(int j=1;j<=n;j++)
{
if(i-3*j+1<=0)
break;
int l = i-3*j+1;
if(s.substr(l-1,3)=="abc")
{
dp[i]=max(dp[i],dp[l]+a[j]);
}
else
break;
}
}
cout<<dp[m]<<"\n";
}
标签:六级,const,int,namespace,cin,C++,1e5,GESP2024
From: https://blog.csdn.net/weixin_60445850/article/details/145318784