A13284 | Letters and Question Marks
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given a string $S$ and an array of strings $[t_1, t_2, \dots, t_k]$ . Each string $t_i$ consists of lowercase Latin letters from a to n; $S$ consists of lowercase Latin letters from a to n and no more than $14$ question marks.
Each string $t_i$ has its cost $c_i$ — an integer number. The value of some string $T$ is calculated as $\sum\limits_{i = 1}^{k} F(T, t_i) \cdot c_i$ , where $F(T, t_i)$ is the number of occurences of string $t_i$ in $T$ as a substring. For example, $F(\text{aaabaaa}, \text{aa}) = 4$ .
You have to replace all question marks in $S$ with pairwise distinct lowercase Latin letters from a to n so the value of $S$ is maximum possible.
Each string $t_i$ has its cost $c_i$ — an integer number. The value of some string $T$ is calculated as $\sum\limits_{i = 1}^{k} F(T, t_i) \cdot c_i$ , where $F(T, t_i)$ is the number of occurences of string $t_i$ in $T$ as a substring. For example, $F(\text{aaabaaa}, \text{aa}) = 4$ .
You have to replace all question marks in $S$ with pairwise distinct lowercase Latin letters from a to n so the value of $S$ is maximum possible.
输入格式
The first line contains one integer $k$ ( $1 \le k \le 1000$ ) — the number of strings in the array $[t_1, t_2, \dots, t_k]$ .
Then $k$ lines follow, each containing one string $t_i$ (consisting of lowercase Latin letters from a to n) and one integer $c_i$ ( $1 \le |t_i| \le 1000$ , $-10^6 \le c_i \le 10^6$ ). The sum of lengths of all strings $t_i$ does not exceed $1000$ .
The last line contains one string $S$ ( $1 \le |S| \le 4 \cdot 10^5$ ) consisting of lowercase Latin letters from a to n and question marks. The number of question marks in $S$ is not greater than $14$ .
Then $k$ lines follow, each containing one string $t_i$ (consisting of lowercase Latin letters from a to n) and one integer $c_i$ ( $1 \le |t_i| \le 1000$ , $-10^6 \le c_i \le 10^6$ ). The sum of lengths of all strings $t_i$ does not exceed $1000$ .
The last line contains one string $S$ ( $1 \le |S| \le 4 \cdot 10^5$ ) consisting of lowercase Latin letters from a to n and question marks. The number of question marks in $S$ is not greater than $14$ .
输出格式
Print one integer — the maximum value of $S$ after replacing all question marks with pairwise distinct lowercase Latin letters from a to n.
输入输出样例
输入 #1
4 abc -10 a 1 b 1 c 3 ?b?
输出 #1
5
输入 #2
2 a 1 a 1 ?
输出 #2
2
输入 #3
3 a 1 b 3 ab 4 ab
输出 #3
8
输入 #4
1 a -1 ?????????????
输出 #4
0
输入 #5
1 a -1 ??????????????
输出 #5
-1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted