CF1327G.Letters and Question Marks
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:1024MB
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.
给你一个字符串 S 和一个字符串数组 [t1,t2,…,tk]。每个字符串 ti 仅由小写拉丁字母 a 到 n 组成;字符串 S 由小写拉丁字母 a 到 n 及至多 14 个问号(?)组成。
每个字符串 ti 都有一个对应的成本 ci —— 一个整数。某个字符串 T 的值定义为 i=1∑kF(T,ti)⋅ci,其中 F(T,ti) 表示子串 ti 在 T 中出现的次数(允许重叠)。例如,F(aaabaaa,aa)=4。
你需要将 S 中的所有问号替换为互不相同的、取自 a 到 n 的小写拉丁字母,使得 S 的值尽可能大。
输入格式
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.
第一行包含一个整数 k(1≤k≤1000)—— 表示数组 [t1,t2,…,tk] 中字符串的个数。
接下来是 k 行,每行包含一个字符串 ti(由小写拉丁字母 a 到 n 组成)和一个整数 ci(1≤∣ti∣≤1000,−106≤ci≤106)。所有字符串 ti 的长度之和不超过 1000。
最后一行包含一个字符串 S(1≤∣S∣≤4⋅105),由小写拉丁字母 a 到 n 和问号组成。字符串 S 中问号的个数不超过 14。
输出格式
Print one integer — the maximum value of S after replacing all question marks with pairwise distinct lowercase Latin letters from a to n.
输出一个整数——将所有问号替换为互不相同的、从 a 到 n 的小写拉丁字母后,S 的最大可能值。
输入输出样例
输入#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
输入解题思路,AI测评打分。不知道怎么写?