#P3736. [HAOI2016] 字符合并

    ID: 1294 远端评测题 1000ms 250MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>2016河南各省省选枚举,暴力状态压缩,状压

[HAOI2016] 字符合并

Description

You are given a 0101 string of length nn. Each time, you may merge kk adjacent characters to obtain a new character and gain a certain score.

The resulting character and the score are determined by these kk characters. You need to find the maximum total score you can obtain.

Input Format

The first line contains two integers, the string length nn and the parameter kk.

The second line contains nn space-separated characters, each either 00 or 11. The ii-th character is the ii-th character of the initial string.

From the 33-rd to the (2k+2)(2^k + 2)-th lines, each line contains one character and one integer. On line (i+2)(i + 2), the character cic_i is the resulting character for the ii-th length-kk 0101 string when these kk-bit strings are interpreted as binary numbers and ordered increasingly; the integer wiw_i is the score for the corresponding ii-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 100%100\% of the testdata, it is guaranteed that:
    • 1n3001 \leq n \leq 300, 1<k81 < k \leq 8.
    • ci{0,1}c_i \in \{0, 1\}, 1wi1091 \leq w_i \leq 10^9.

Translated by ChatGPT 5