SnowflakeOA #3
String Transformation — Suffix Removal Then Prepend
Estimated HardJudge-ready
Topics (AI-labelled)DP BasicsStringsBits & Math
In each step, choose a non-empty proper suffix and move it to the front of the string; the string must become the target after exactly k steps. Different sequences of cut points are counted separately, even if the string is periodic. Output the answer modulo 10⁹+7.
Input
Three lines: src, target, and k. Each string has length 2..1000, 1≤k≤10⁶, and characters are a..z.
Output
Output the single integer required by the problem.
Example 1
Input:
ababab
ababab
1
Output:
2
Example 2
Input:
aaaa
aaaa
2
Output:
9
Example 3
Input:
ab
ba
2
Output:
0
Example notes
The answers to the three public examples are, in order: 2; 9; 0. All examples have been verified by independent small-scale enumeration or state search.
Editorial
Loading solution…