A12635 | Mysterious Code
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line contains string $c$ ( $1 \leq |c| \leq 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 \leq |s|, |t| \leq 50$ , $s \neq t$ ). It is guaranteed that $s$ and $t$ consist of lowercase English characters only.
The second and third line contain strings $s$ and $t$ respectively ( $1 \leq |s|, |t| \leq 50$ , $s \neq t$ ). It is guaranteed that $s$ and $t$ consist of lowercase English characters only.
输出格式
Print a single integer — the largest possible value of $f(c', s) - f(c', t)$ of the recovered code.
输入输出样例
输入 #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$ .
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++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted