CF1327G.Letters and Question Marks
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given a string S and an array of strings [t1,t2,…,tk] . Each string ti 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 ti has its cost ci — an integer number. The value of some string T is calculated as i=1∑kF(T,ti)⋅ci , where F(T,ti) is the number of occurences of string ti in T as a substring. For example, F(aaabaaa,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≤k≤1000 ) — the number of strings in the array [t1,t2,…,tk] .
Then k lines follow, each containing one string ti (consisting of lowercase Latin letters from a to n) and one integer ci ( 1≤∣ti∣≤1000 , −106≤ci≤106 ). The sum of lengths of all strings ti does not exceed 1000 .
The last line contains one string S ( 1≤∣S∣≤4⋅105 ) 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