#P3736. [HAOI2016] 字符合并
[HAOI2016] 字符合并
Description
You are given a string of length . Each time, you may merge adjacent characters to obtain a new character and gain a certain score.
The resulting character and the score are determined by these characters. You need to find the maximum total score you can obtain.
Input Format
The first line contains two integers, the string length and the parameter .
The second line contains space-separated characters, each either or . The -th character is the -th character of the initial string.
From the -rd to the -th lines, each line contains one character and one integer. On line , the character is the resulting character for the -th length- string when these -bit strings are interpreted as binary numbers and ordered increasingly; the integer is the score for the corresponding -th pattern.
Output Format
Output a single integer denoting the answer.
3 2
1 0 1
1 10
1 10
0 20
1 30
40
Hint
Constraints
- For of the testdata, it is guaranteed that:
- , .
- , .
Translated by ChatGPT 5
京公网安备 11011102002149号