题意:给定01串,若删去连续i个0/1的子串,可得到a[i]分数,能获得分数的最大值
总是不会暴力。。其实不难
设d[x][y][k]为区间[x,y]内且与第i个字符形成的连续k个0/1子串的最大值
那么有2个方面的转移
一个是枚举i,使得[x,i]贡献一个0/1,[i,y]贡献k-1个0/1
一个是枚举i,使得[x,i]贡献k个0/1,[i,y]贡献他所能贡献的最大值
E. Vasya and Binary String
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Vasya has a string ?
of length ? consisting only of digits 0 and 1. Also he has an array ? of length ?
.
Vasya performs the following operation until the string becomes empty: choose some consecutive substring of equal characters, erase it from the string and glue together the remaining parts (any of them can be empty). For example, if he erases substring 111 from string 111110 he will get the string 110. Vasya gets ??
points for erasing substring of length ?
.
Vasya wants to maximize his total points, so help him with this!
Input
The first line contains one integer ?
(1≤?≤100) — the length of string ?
.
The second line contains string ?
, consisting only of digits 0 and 1.
The third line contains ?
integers ?1,?2,…?? (1≤??≤109), where ?? is the number of points for erasing the substring of length ?
.
Output
Print one integer — the maximum total points Vasya can get.
Examples
Input
Copy
7 1101001 3 4 9 100 1 2 3
Output
Copy
109
Input
Copy
5 10101 3 10 15 15 15
Output
Copy
23
Note
In the first example the optimal sequence of erasings is: 1101001 →
111001 → 11101 → 1111 → ∅
.
In the second example the optimal sequence of erasings is: 10101 →
1001 → 11 → ∅
.