307306: CF1336C. Kaavi and Magic Spell
Memory Limit:512 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Kaavi and Magic Spell
题意翻译
给定一个字符串 $S$ 和一个字符串 $T$,每次可以删掉 $S$ 的第一个字符,然后放到一个初始为空的字符串 $A$ 的首部或尾部,求有多少种不同的方法使得最后 $T$ 是 $A$ 的前缀。题目描述
Kaavi, the mysterious fortune teller, deeply believes that one's fate is inevitable and unavoidable. Of course, she makes her living by predicting others' future. While doing divination, Kaavi believes that magic spells can provide great power for her to see the future. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/CF1336C/28f922a8d61b005da66667b890172094e2d89686.png) Kaavi has a string $ T $ of length $ m $ and all the strings with the prefix $ T $ are magic spells. Kaavi also has a string $ S $ of length $ n $ and an empty string $ A $ . During the divination, Kaavi needs to perform a sequence of operations. There are two different operations: - Delete the first character of $ S $ and add it at the front of $ A $ . - Delete the first character of $ S $ and add it at the back of $ A $ . Kaavi can perform no more than $ n $ operations. To finish the divination, she wants to know the number of different operation sequences to make $ A $ a magic spell (i.e. with the prefix $ T $ ). As her assistant, can you help her? The answer might be huge, so Kaavi only needs to know the answer modulo $ 998\,244\,353 $ . Two operation sequences are considered different if they are different in length or there exists an $ i $ that their $ i $ -th operation is different. A substring is a contiguous sequence of characters within a string. A prefix of a string $ S $ is a substring of $ S $ that occurs at the beginning of $ S $ .输入输出格式
输入格式
The first line contains a string $ S $ of length $ n $ ( $ 1 \leq n \leq 3000 $ ). The second line contains a string $ T $ of length $ m $ ( $ 1 \leq m \leq n $ ). Both strings contain only lowercase Latin letters.
输出格式
The output contains only one integer — the answer modulo $ 998\,244\,353 $ .
输入输出样例
输入样例 #1
abab
ba
输出样例 #1
12
输入样例 #2
defineintlonglong
signedmain
输出样例 #2
0
输入样例 #3
rotator
rotator
输出样例 #3
4
输入样例 #4
cacdcdbbbb
bdcaccdbbb
输出样例 #4
24