'commit'
This commit is contained in:
37
GESP/Level6/20240601.cpp
Normal file
37
GESP/Level6/20240601.cpp
Normal file
@@ -0,0 +1,37 @@
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user