CF163A.Substring and Subsequence

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

One day Polycarpus got hold of two non-empty strings ss and tt , consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of " xx yy " are there, such that xx is a substring of string ss , yy is a subsequence of string tt , and the content of xx and yy is the same. Two pairs are considered different, if they contain different substrings of string ss or different subsequences of string tt . Read the whole statement to understand the definition of different substrings and subsequences.

The length of string ss is the number of characters in it. If we denote the length of the string ss as s|s| , we can write the string as s=s1s2... sss=s_{1}s_{2}...\ s_{|s|} .

A substring of ss is a non-empty string x=s[a... b]=sasa+1... sbx=s[a...\ b]=s_{a}s_{a+1}...\ s_{b} ( 1<=a<=b<=s1<=a<=b<=|s| ). For example, "code" and "force" are substrings or "codeforces", while "coders" is not. Two substrings s[a... b]s[a...\ b] and s[c... d]s[c...\ d] are considered to be different if aca≠c or bdb≠d . For example, if ss ="codeforces", s[2...2]s[2...2] and s[6...6]s[6...6] are different, though their content is the same.

A subsequence of ss is a non-empty string y=s[p1p2... py]=sp1sp2... spyy=s[p_{1}p_{2}...\ p_{|y|}]=s_{p1}s_{p2}...\ s_{p|y|} ( 1<=p_{1}<p_{2}<...<p_{|y|}<=|s| ). For example, "coders" is a subsequence of "codeforces". Two subsequences u=s[p1p2... pu]u=s[p_{1}p_{2}...\ p_{|u|}] and v=s[q1q2... qv]v=s[q_{1}q_{2}...\ q_{|v|}] are considered different if the sequences pp and qq are different.

输入格式

The input consists of two lines. The first of them contains ss ( 1<=s<=50001<=|s|<=5000 ), and the second one contains tt ( 1<=t<=50001<=|t|<=5000 ). Both strings consist of lowercase Latin letters.

输出格式

Print a single number — the number of different pairs " xx yy " such that xx is a substring of string ss , yy is a subsequence of string tt , and the content of xx and yy is the same. As the answer can be rather large, print it modulo 10000000071000000007 (109+7)(10^{9}+7) .

输入输出样例

  • 输入#1

    aa
    aa
    

    输出#1

    5
    
  • 输入#2

    codeforces
    forceofcode
    

    输出#2

    60
    

说明/提示

Let's write down all pairs " xx yy " that form the answer in the first sample: " s[1...1]s[1...1] t[1]t[1] ", " s[2...2]s[2...2] t[1]t[1] ", " s[1...1]s[1...1] t[2]t[2] "," s[2...2]s[2...2] t[2]t[2] ", " s[1...2]s[1...2] t[1 2]t[1 2] ".

首页