CF1163D.Mysterious Code
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
During a normal walk in the forest, Katie has stumbled upon a mysterious code! However, the mysterious code had some characters unreadable. She has written down this code as a string c consisting of lowercase English characters and asterisks ("*"), where each of the asterisks denotes an unreadable character. Excited with her discovery, Katie has decided to recover the unreadable characters by replacing each asterisk with arbitrary lowercase English letter (different asterisks might be replaced with different letters).
Katie has a favorite string s and a not-so-favorite string t and she would love to recover the mysterious code so that it has as many occurrences of s as possible and as little occurrences of t as possible. Formally, let's denote f(x,y) as the number of occurrences of y in x (for example, f(aababa,ab)=2). Katie wants to recover the code c′ conforming to the original c, such that f(c′,s)−f(c′,t) is largest possible. However, Katie is not very good at recovering codes in general, so she would like you to help her out.
凯蒂在森林中正常散步时,偶然发现了一段神秘的密码!然而,这段神秘密码中有一些字符无法辨认。她将这段密码记录为一个字符串 c,其中包含小写英文字母和星号(\*),每个星号代表一个无法辨认的字符。出于对这一发现的兴奋,凯蒂决定通过将每个星号替换为任意一个小写英文字母(不同星号可被替换为不同字母)来恢复这些不可读的字符。
凯蒂有一个最喜爱的字符串 s 和一个不太喜欢的字符串 t,她希望恢复后的神秘密码能尽可能多地包含 s,同时尽可能少地包含 t。形式化地,记 f(x,y) 为字符串 y 在字符串 x 中的出现次数(例如,f(aababa,ab)=2)。凯蒂希望恢复出一个符合原始字符串 c 约束的字符串 c′,使得 f(c′,s)−f(c′,t) 的值尽可能大。然而,凯蒂通常并不擅长解码,因此她希望你能帮她解决这个问题。
输入格式
The first line contains string c (1≤∣c∣≤1000) — the mysterious code . It is guaranteed that c consists of lowercase English characters and asterisks "*" only.
The second and third line contain strings s and t respectively (1≤∣s∣,∣t∣≤50, s=t). It is guaranteed that s and t consist of lowercase English characters only.
第一行包含字符串 c(1≤∣c∣≤1000)——即神秘代码。保证 c 仅由小写英文字母和星号 “*” 组成。
第二行和第三行分别包含字符串 s 和 t(1≤∣s∣,∣t∣≤50,且 s=t)。保证 s 和 t 仅由小写英文字母组成。
输出格式
Print a single integer — the largest possible value of f(c′,s)−f(c′,t) of the recovered code.
输出一个整数——恢复后的代码中 f(c′,s)−f(c′,t) 的最大可能值。
输入输出样例
输入#1
***** katie shiro
输出#1
1
输入#2
caat caat a
输出#2
-1
输入#3
*a* bba b
输出#3
0
输入#4
*** cc z
输出#4
2
说明/提示
In the first example, for c′ equal to "katie" f(c′,s)=1 and f(c′,t)=0, which makes f(c′,s)−f(c′,t)=1 which is the largest possible.
In the second example, the only c′ conforming to the given c is "caat". The corresponding f(c′,s)−f(c′,t)=1−2=−1.
In the third example, there are multiple ways to recover the code such that f(c′,s)−f(c′,t) is largest possible, for example "aaa", "aac", or even "zaz". The value of f(c′,s)−f(c′,t)=0 for all of these recovered codes.
In the fourth example, the optimal recovered code c′ would be "ccc". The corresponding f(c′,s)−f(c′,t)=2.
在第一个例子中,当 c′ 为 “katie” 时,有 f(c′,s)=1 且 f(c′,t)=0,因此 f(c′,s)−f(c′,t)=1,这是可能的最大值。
在第二个例子中,唯一符合给定 c 的 c′ 是 “caat”。对应的 f(c′,s)−f(c′,t)=1−2=−1。
在第三个例子中,存在多种方式恢复代码,使得 f(c′,s)−f(c′,t) 达到最大值,例如 “aaa”、“aac”,甚至 “zaz”。对于所有这些恢复出的代码,均有 f(c′,s)−f(c′,t)=0。
在第四个例子中,最优的恢复代码 c′ 是 “ccc”。对应的 f(c′,s)−f(c′,t)=2。
输入解题思路,AI测评打分。不知道怎么写?