A15272 | Cut Substrings
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
You are given two non-empty strings $s$ and $t$ , consisting of Latin letters.
In one move, you can choose an occurrence of the string $t$ in the string $s$ and replace it with dots.
Your task is to remove all occurrences of the string $t$ in the string $s$ in the minimum number of moves, and also calculate how many different sequences of moves of the minimum length exist.
Two sequences of moves are considered different if the sets of indices at which the removed occurrences of the string $t$ in $s$ begin differ. For example, the sets $\{1, 2, 3\}$ and $\{1, 2, 4\}$ are considered different, the sets $\{2, 4, 6\}$ and $\{2, 6\}$ — too, but sets $\{3, 5\}$ and $\{5, 3\}$ — not.
For example, let the string $s =$ "abababacababa" and the string $t =$ "aba". We can remove all occurrences of the string $t$ in $2$ moves by cutting out the occurrences of the string $t$ at the $3$ th and $9$ th positions. In this case, the string $s$ is an example of the form "ab...bac...ba". It is also possible to cut occurrences of the string $t$ at the $3$ th and $11$ th positions. There are two different sequences of minimum length moves.
Since the answer can be large, output it modulo $10^9 + 7$ .
In one move, you can choose an occurrence of the string $t$ in the string $s$ and replace it with dots.
Your task is to remove all occurrences of the string $t$ in the string $s$ in the minimum number of moves, and also calculate how many different sequences of moves of the minimum length exist.
Two sequences of moves are considered different if the sets of indices at which the removed occurrences of the string $t$ in $s$ begin differ. For example, the sets $\{1, 2, 3\}$ and $\{1, 2, 4\}$ are considered different, the sets $\{2, 4, 6\}$ and $\{2, 6\}$ — too, but sets $\{3, 5\}$ and $\{5, 3\}$ — not.
For example, let the string $s =$ "abababacababa" and the string $t =$ "aba". We can remove all occurrences of the string $t$ in $2$ moves by cutting out the occurrences of the string $t$ at the $3$ th and $9$ th positions. In this case, the string $s$ is an example of the form "ab...bac...ba". It is also possible to cut occurrences of the string $t$ at the $3$ th and $11$ th positions. There are two different sequences of minimum length moves.
Since the answer can be large, output it modulo $10^9 + 7$ .
输入格式
The first line of the input contains a single integer $q$ ( $1 \le q \le 50$ ) — the number of test cases. The descriptions of the sets follow.
The first line of each set contains a non-empty string $s$ ( $1 \le |s| \le 500$ ) consisting of lowercase Latin letters.
The second line of each set contains a non-empty string $t$ ( $1 \le |t| \le 500$ ) consisting of lowercase Latin letters.
It is guaranteed that the sum of string lengths $s$ over all test cases does not exceed $500$ . Similarly, it is guaranteed that the sum of string lengths $t$ over all test cases does not exceed $500$ .
The first line of each set contains a non-empty string $s$ ( $1 \le |s| \le 500$ ) consisting of lowercase Latin letters.
The second line of each set contains a non-empty string $t$ ( $1 \le |t| \le 500$ ) consisting of lowercase Latin letters.
It is guaranteed that the sum of string lengths $s$ over all test cases does not exceed $500$ . Similarly, it is guaranteed that the sum of string lengths $t$ over all test cases does not exceed $500$ .
输出格式
For each test case print two integers — the minimum number of moves and the number of different optimal sequences, modulo $10^9 + 7$ .
输入输出样例
输入 #1
8 abababacababa aba ddddddd dddd xyzxyz xyz abc abcd abacaba abaca abc def aaaaaaaa a aaaaaaaa aa
输出 #1
2 2 1 4 2 1 0 1 1 1 0 1 8 1 3 6
The first test case is explained in the statement.
In the second case, it is enough to cut any of the four occurrences.
In the third case, string $s$ is the concatenation of two strings $t =$ "xyz", so there is a unique optimal sequence of $2$ moves.
In the fourth and sixth cases, the string $s$ initially contains no occurrences of the string $t$ .
In the fifth case, the string $s$ contains exactly one occurrence of the string $t$ .
In the second case, it is enough to cut any of the four occurrences.
In the third case, string $s$ is the concatenation of two strings $t =$ "xyz", so there is a unique optimal sequence of $2$ moves.
In the fourth and sixth cases, the string $s$ initially contains no occurrences of the string $t$ .
In the fifth case, the string $s$ contains exactly one occurrence of the string $t$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted