CF1729G.Cut Substrings

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given two non-empty strings ss and tt , consisting of Latin letters.

In one move, you can choose an occurrence of the string tt in the string ss and replace it with dots.

Your task is to remove all occurrences of the string tt in the string ss 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 tt in ss begin differ. For example, the sets {1,2,3}\{1, 2, 3\} and {1,2,4}\{1, 2, 4\} are considered different, the sets {2,4,6}\{2, 4, 6\} and {2,6}\{2, 6\} — too, but sets {3,5}\{3, 5\} and {5,3}\{5, 3\} — not.

For example, let the string s=s = "abababacababa" and the string t=t = "aba". We can remove all occurrences of the string tt in 22 moves by cutting out the occurrences of the string tt at the 33 th and 99 th positions. In this case, the string ss is an example of the form "ab...bac...ba". It is also possible to cut occurrences of the string tt at the 33 th and 1111 th positions. There are two different sequences of minimum length moves.

Since the answer can be large, output it modulo 109+710^9 + 7 .

输入格式

The first line of the input contains a single integer qq ( 1q501 \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 ss ( 1s5001 \le |s| \le 500 ) consisting of lowercase Latin letters.

The second line of each set contains a non-empty string tt ( 1t5001 \le |t| \le 500 ) consisting of lowercase Latin letters.

It is guaranteed that the sum of string lengths ss over all test cases does not exceed 500500 . Similarly, it is guaranteed that the sum of string lengths tt over all test cases does not exceed 500500 .

输出格式

For each test case print two integers — the minimum number of moves and the number of different optimal sequences, modulo 109+710^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 ss is the concatenation of two strings t=t = "xyz", so there is a unique optimal sequence of 22 moves.

In the fourth and sixth cases, the string ss initially contains no occurrences of the string tt .

In the fifth case, the string ss contains exactly one occurrence of the string tt .

首页