Files
python/GESP/Level6/20240601.cpp
HuangHai 1f397eca87 'commit'
2025-08-30 18:35:01 +08:00

37 lines
997 B
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[30];
string s;
int f[N]; // f[i]表示前i个字符的最大分值
int main() {
#ifndef ONLINE_JUDGE
freopen("20240601.in", "r", stdin);
#endif
int n;
cin >> n;
// 连续多个abc的分值
for (int i = 1; i <= n; i++)
cin >> a[i];
int m; // 字符串的长度
cin >> m >> s; // 字符串
for (int i = 1; i <= m; i++) { // 枚举每个字符
f[i] = f[i - 1]; // 从前面继承分值
for (int j = 1; j <= n; j++) { // 枚举每个分值,看看有没有机会得到这个分值,就是1个2个3个abc...
int start = i - 3 * j;
if (start < 0)
break;
if (s.substr(start, 3) == "abc") // 最后一组是abc,那么有机会获得更高分值
f[i] = max(f[i], f[start + 1] + a[j]);
else
break; // 不是abc,没有继续检查的必要
}
}
cout << f[m] << endl;
return 0;
}