#P10721. [GESP202406 六级] 计算得分
[GESP202406 六级] 计算得分
Background
Related multiple-choice and true/false problems: https://ti.luogu.com.cn/problemset/1154.
Problem Description
Xiao Yang wants to calculate the score of a string consisting of lowercase letters.
Xiao Yang sets a scoring sequence of positive integers. If a substring of the string is formed by concatenating copies of end to end, then it can gain a score of . Also, characters in the string cannot be counted repeatedly for scoring. The total score of the whole string is the sum of the scores of the scoring substrings.
For example, suppose the string is . All possible scoring methods are as follows:
- or , where and do not score, and the total score is .
- , and the total score is .
- , and the total score is .
Xiao Yang wants to know, for a given string, what the maximum total score is.
Input Format
-
The first line contains a positive integer , representing the length of the scoring sequence .
-
The second line contains positive integers, representing the scoring sequence .
-
The third line contains a positive integer , representing the length of the string.
-
The fourth line contains a string of lowercase letters.
Output Format
Output one integer, representing the maximum total score of the given string.
3
3 1 2
13
dabcabcabcabz
9
Hint
Sample Explanation
The best scoring method is , and the total score is , which is points in total.
Constraints
| Subtask ID | Percentage | Special Property | |||
|---|---|---|---|---|---|
| For all , there exists | |||||
For all testdata, it is guaranteed that , , and .
Translated by ChatGPT 5