A12276 | Vasya and Binary String
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya has a string $s$ of length $n$ consisting only of digits 0 and 1. Also he has an array $a$ of length $n$ .
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 $a_x$ points for erasing substring of length $x$ .
Vasya wants to maximize his total points, so help him with this!
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 $a_x$ points for erasing substring of length $x$ .
Vasya wants to maximize his total points, so help him with this!
输入格式
The first line contains one integer $n$ ( $1 \le n \le 100$ ) — the length of string $s$ .
The second line contains string $s$ , consisting only of digits 0 and 1.
The third line contains $n$ integers $a_1, a_2, \dots a_n$ ( $1 \le a_i \le 10^9$ ), where $a_i$ is the number of points for erasing the substring of length $i$ .
The second line contains string $s$ , consisting only of digits 0 and 1.
The third line contains $n$ integers $a_1, a_2, \dots a_n$ ( $1 \le a_i \le 10^9$ ), where $a_i$ is the number of points for erasing the substring of length $i$ .
输出格式
Print one integer — the maximum total points Vasya can get.
输入输出样例
输入 #1
7 1101001 3 4 9 100 1 2 3
输出 #1
109
输入 #2
5 10101 3 10 15 15 15
输出 #2
23
In the first example the optimal sequence of erasings is: 1101001 $\rightarrow$ 111001 $\rightarrow$ 11101 $\rightarrow$ 1111 $\rightarrow$ $\varnothing$ .
In the second example the optimal sequence of erasings is: 10101 $\rightarrow$ 1001 $\rightarrow$ 11 $\rightarrow$ $\varnothing$ .
In the second example the optimal sequence of erasings is: 10101 $\rightarrow$ 1001 $\rightarrow$ 11 $\rightarrow$ $\varnothing$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted